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

📄 wmlelm.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * 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.
 */
/*========================================================================
	FILE: wmlelm.c
  
	Source for WML-specific element handler.

	Rev history:
		980706	JPR		Created
		981223	JPR		Event concept changed	
		990303	JPR		Corrections
		990316	JPR		Major changes. Handles the WML-specific 
						elements. Variable handling moved to 
						WMLIF.c
		990317	JPR		Corrections
		990325	JPR		WAP 1.1
		990412	JPR		Uses Url.h instead of Url_lib.h
		990421	JPR		Corr. in WML_CreateINPUT and WML_SetFormat
		990428	JPR		Support for LITERALS added
		990526	JPR		Paragraph updates
		990610	JPR		Removal of unreferenced variables
		991026	JPR		WTA specific parts added

		991202	JPR		Changes to support new generic WBXML-decoder
		991208	JPR		Minor corrections
		991223	JPR		fLastOption in OPTIONELEMENT removed
		000104	JPR		xml:lang, xml:space and pre element added
		000113	JPR		Correction in WML_CreateP
		000131	JPR		Functions WML_AddContent and WML_GetContent
						updated.
		000201	JPR		Corrections in Set-functions for attributes and
						in WML_CreateINPUT, WML_CreateBR created
		000210	JPR		Correction in function WML_CreateElement
		000225	JPR		Function WML_SetXmlSpace updated
		000308	JPR		Corrections in WTA Event handling 
		000419	JPR		Functions WML_SetWidth and WML_SetHeight corrected
						Default value "unknown" added for attribute "type"
						in do element
		000809	JPR		Addition of "cache-control" attribute in go
		010119	NKE		Replaced WML_AddContent with WML_ValidContent
						for the new decoder in wbxmldec.c.
		010126	NKE		Changed WML_GetContent. Added new functionality to
						WML_CreateElement to be able to handle complete wml
						documents and not as before only cards. This functionality
						has ben moved from wmlif.c/WML_ParseNextElement().

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


#include "url.h"
#include "cmmnrsrc.h"
#include "wmldef.h"
#include "wmltoken.h"
#include "wmlevent.h"
#include "wmlelm.h" 
#include "waectype.h"
#include "wmlparse.h"
#include "wbxmlelm.h"
#include "wipprdct.h"



/*========================================================================
	WML_ConvertEventToInt
==========================================================================*/
INT8 WML_ConvertEventToInt (WCHAR** ppchType)
{
	const WCHAR pchConst_OnEnterForward[]={'o','n','e','n','t','e','r','f','o','r','w','a','r','d',0};
	const WCHAR pchConst_OnEnterBackward[]={'o','n','e','n','t','e','r','b','a','c','k','w','a','r','d',0};
	const WCHAR pchConst_OnTimer[]={'o','n','t','i','m','e','r',0};
	const WCHAR pchConst_OnClick[]={'o','n','p','i','c','k',0};

	if (*ppchType!=NULL) 
	{
		if (COMPARESTRING(*ppchType,pchConst_OnEnterForward)==0) 
		{
			/* DEALLOC must be on pchType, not on &pchType since
			   the parameter is **pchType. */
			DEALLOC(ppchType);
			return DEF_TYPE_ONENTERFORWARD;
		} 
		else if (COMPARESTRING(*ppchType,pchConst_OnEnterBackward)==0) 
		{
			DEALLOC(ppchType);
			return DEF_TYPE_ONENTERBACKWARD;
		} 
		else if (COMPARESTRING(*ppchType,pchConst_OnTimer)==0) 
		{
			DEALLOC(ppchType);
			return DEF_TYPE_ONTIMER;
		} 
		else if (COMPARESTRING(*ppchType,pchConst_OnClick)==0) 
		{
			DEALLOC(ppchType);
			return DEF_TYPE_ONCLICK;
		}
		else
		{
			DEALLOC(ppchType);
		}
	}

	return DEF_TYPE_UNKNOWN;
}


/*========================================================================
	WML_ConvertEventToInt
==========================================================================*/
INT8 WML_ConvertInputToInt (WCHAR** ppchType)
{
	const WCHAR pchConst_Text[]={'t','e','x','t',0};
	const WCHAR pchConst_Password[]={'p','a','s','s','w','o','r','d',0};

	if (*ppchType!=NULL) 
	{
		if (COMPARESTRING(*ppchType,pchConst_Text)==0) 
		{
			DEALLOC(ppchType);
			return DEF_TYPE_TEXT;
		} 
		else if (COMPARESTRING(*ppchType,pchConst_Password)==0) 
		{
			DEALLOC(ppchType);
			return DEF_TYPE_PASSWORD;
		} 
		else
		{
			DEALLOC(ppchType);
		}
	}

	return DEF_TYPE_UNKNOWN;
}


/* WTA specific */
#ifdef CONFIG_WTA
/*========================================================================
	WTA_ConvertEventToInt
==========================================================================*/
INT8 WTA_ConvertEventToInt (WCHAR *pwchType)
{
	INT8 iResult=DEF_TYPE_UNKNOWN;
	INT16 iIndex=-1;
	UINT16 iLength=0;
	WCHAR *pwchTemp=pwchType;
	const WCHAR pwchWtaev[]={'w','t','a','e','v','-',0};

	if (pwchType!=NULL) 
	{
		/* Remove 'wtaev-' from type */

		/* Get length of pwchPId string */
		iLength=(UINT16) (w_strlen(pwchType));

		/* Length must be greater than 6 */
		if ( iLength > 6 )
		{
			if (COMPARESTRINGN(pwchWtaev,pwchType,6)==0)
			{
				/* String starts with 'wtaev-' -> step 6 WCHARs */
				pwchTemp+=6;
			}

			/* Compare (Network common) */
			iIndex=FindStringBinarySearch(pwchTemp,ppwchWTAEvents,STAT_NBROFWTAEVENTS);

			if (iIndex>=0)
			{
				iResult=pbWTAEventBytes[iIndex];
			}


			/* Compare (Network GSM) */
			#ifdef CONFIG_WTAI_GSM

			iIndex=FindStringBinarySearch(pwchTemp,ppwchGSMWTAEvents,STAT_NBROFGSMEVENTS);

			if (iIndex>=0)
			{
				iResult=pbGSMWTAEventBytes[iIndex];
			}

			#endif

			
			/* No events defined for CONFIG_WTAI_PDC */
		

			/* Compare (Network IS 136) */
			#ifdef CONFIG_WTAI_IS_136

			iIndex=FindStringBinarySearch(pwchTemp,ppwchIS136WTAEvents,STAT_NBROFIS136EVENTS);

			if (iIndex>=0)
			{
				iResult=pbIS136WTAEventBytes[iIndex];
			}

			#endif	
		}
	}

	return iResult;
}
#endif


/*========================================================================
	WML_ConvertAlign
==========================================================================*/
INT8 WML_ConvertAlign (WCHAR **ppchAlign)
{
	const WCHAR pchConst_left[]={'l','e','f','t',0};
	const WCHAR pchConst_center[]={'c','e','n','t','e','r',0};
	const WCHAR pchConst_right[]={'r','i','g','h','t',0};
	const WCHAR pchConst_bottom[]={'b','o','t','t','o','m',0};
	const WCHAR pchConst_middle[]={'m','i','d','d','l','e',0};
	const WCHAR pchConst_top[]={'t','o','p',0};

	if (*ppchAlign!=NULL) 
	{
		if (COMPARESTRING(*ppchAlign,pchConst_left)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_LEFT;
		} 
		else if (COMPARESTRING(*ppchAlign,pchConst_center)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_CENTER;
		} 
		else if (COMPARESTRING(*ppchAlign,pchConst_right)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_RIGHT;
		} 
		else if (COMPARESTRING(*ppchAlign,pchConst_bottom)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_BOTTOM;
		} 
		else if (COMPARESTRING(*ppchAlign,pchConst_middle)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_MIDDLE;
		} 
		else if (COMPARESTRING(*ppchAlign,pchConst_top)==0) 
		{
			DEALLOC(ppchAlign);
			return ALIGN_TOP;
		} 

		DEALLOC(ppchAlign);
	}
	return DEF_TYPE_UNKNOWN;
}

enum WrapMode WML_ConvertMode (WCHAR *pchMode)
{
	const WCHAR pchConst_wrap[]={'w','r','a','p',0};
	const WCHAR pchConst_Nowrap[]={'n','o','w','r','a','p',0};
	
	if (pchMode!=NULL) 
	{
		if (COMPARESTRING(pchMode,pchConst_wrap)==0) 
		{
			DEALLOC(&pchMode);
			return P_Wrap;
		} 
		else if (COMPARESTRING(pchMode,pchConst_Nowrap)==0) 
		{
			DEALLOC(&pchMode);
			return P_NoWrap;
		} 
		DEALLOC(&pchMode);
	}
	return P_Unknown;
}
	
enum MethodType WML_ConvertMethod (WCHAR *pchMethod)
{
	const WCHAR pchConst_post[]={'p','o','s','t',0};
	
	if (pchMethod!=NULL) 
	{
		if (COMPARESTRING(pchMethod,pchConst_post)==0) 
		{
			DEALLOC(&pchMethod);
			return M_Post;
		} 
		DEALLOC(&pchMethod);
	}
	return M_Get;
}

enum CacheControl WML_ConvertCacheControl (WCHAR **ppwchCache)
{
	const WCHAR pwchConst_nocache[]={'n','o','-','c','a','c','h','e',0};
	
	if (*ppwchCache!=NULL) 
	{
		if (COMPARESTRING(*ppwchCache,pwchConst_nocache)==0) 
		{
			DEALLOC(ppwchCache);
			return Cache_nocache;
		} 
		DEALLOC(ppwchCache);
	}
	return Cache_unknown;
}

UINT8 WML_ConvertEnctype (WCHAR **ppwchEnctype)
{
	const WCHAR pchConst_formdata[]={'m','u','l','t','i','p','a','r','t',
							   '/','f','o','r','m','-','d','a','t','a',0};

	if (*ppwchEnctype!=NULL) 
	{
		if (COMPARESTRING(*ppwchEnctype,pchConst_formdata)==0) 
		{
			DEALLOC(ppwchEnctype);
			return GO_formdata;
		} 
		DEALLOC(ppwchEnctype);
	}
	return GO_urlencoded;
}

/* --------------------------------------------- */



/* ---------------------------------------------------
    Functions for handling the WML specific elements.
   --------------------------------------------------- */


/*========================================================================
	WML_AddTemplateDO
==========================================================================*/
BOOL WML_AddTemplateDO (pELEMENTTYPE pCard, pELEMENTTYPE pDO)
{
	pTEMPLATEDOTYPE pTemp=NULL;
	pTEMPLATEDOTYPE pLast=NULL;
	pTEMPLATEDOTYPE pNew=NULL; 
	pCARDELEMENT pCardElm=NULL;
	BOOL fCont=TRUE;

	/* ASSERT:	pCard!=NULL
				pDO!=NULL
	*/

	pNew=NEWSTRUCT(TEMPLATEDOTYPE);

	pCardElm=(CARDELEMENT*)(pCard);

	if (pCardElm!=NULL)
	{
		if (pNew!=NULL)
		{
			pNew->pDO=pDO;
			pNew->pNext=NULL;

			/* Insert at the end of the list */
			pTemp=pCardElm->pTemplateDO;

			if (pTemp==NULL)
			{
				/* List empty */
				pCardElm->pTemplateDO=pNew;
			}
			else
			{
				while ((pTemp!=NULL)&&(fCont))
				{
					pLast=pTemp;

					if (pLast->pNext==NULL)
					{
						/* Last element */
						pLast->pNext=pNew;
						fCont=FALSE;
					}
					pTemp=pTemp->pNext;
				}
			}
			return TRUE;
		}
	}
	return FALSE;
}

/* Deletes the TemplateDO list on the card */
void WML_DeleteTemplateDO (pTEMPLATEDOTYPE pTemplateDO)
{
	pTEMPLATEDOTYPE pTemp;

	while (pTemplateDO!=NULL)
	{
		pTemp=pTemplateDO;
		pTemplateDO=pTemplateDO->pNext;
		DEALLOC(&pTemp);
	}
}


/* Used in all b, big, em, i, small, strong and u-elements */
pEMPHELEMENT WML_CreateEMPH (UINT16 iType) 
{
	pEMPHELEMENT pElement=NEWSTRUCT(EMPHELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=iType;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pContent=NULL;
		pElement->pwchXmlLang=NULL;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pAELEMENT WML_CreateA (void) 
{
	pAELEMENT pElement=NEWSTRUCT(AELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=Type_A;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pTitle=NULL;
		pElement->pHref=NULL;
		pElement->pContent=NULL;
		pElement->pwchXmlLang=NULL;
		pElement->wchAccessKey=0;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pANCHORELEMENT WML_CreateANCHOR (void) 
{
	pANCHORELEMENT pElement=NEWSTRUCT(ANCHORELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=Type_ANCHOR;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pTitle=NULL;
		pElement->pContent=NULL;
		pElement->pwchXmlLang=NULL;
		pElement->wchAccessKey=0;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pACCESSELEMENT WML_CreateACCESS (void) 
{
	pACCESSELEMENT pElement=NEWSTRUCT(ACCESSELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=Type_ACCESS;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pchDomain=NULL;
		pElement->pchPath=NULL;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pBRELEMENT WML_CreateBR (void) 
{
	pBRELEMENT pElement=NEWSTRUCT(BRELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=Type_BR;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pwchXmlLang=NULL;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pCARDELEMENT WML_CreateCARD (void) 
{
	pCARDELEMENT pElement=NEWSTRUCT(CARDELEMENT);

	#ifndef HAS_SETJMP
	if (pElement!=NULL) 
	{
	#endif

		pElement->iType=Type_CARD;
		pElement->pNextElement=NULL;

		/* Element specific */
		pElement->pchId=NULL;
		pElement->pTitle=NULL;
		pElement->fNewContext=FALSE;
		pElement->fOrdered=TRUE;
		pElement->pOnEntForw=NULL;
		pElement->pOnEntBack=NULL;
		pElement->pOnTimer=NULL;
		pElement->pContent=NULL;
		pElement->pEventTab=NULL;
		pElement->pTemplateDO=NULL;
		pElement->pwchXmlLang=NULL;

	#ifndef HAS_SETJMP
	}
	#endif

	return pElement;
}

pDOELEMENT WML_CreateDO (void) 
{
	pDOELEMENT pElement=NEWSTRUCT(DOELEMENT);

⌨️ 快捷键说明

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