📄 wmlparse.c
字号:
/*
* 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: wmlparse.c
Source for WML-specific parse
Rev history:
980706 JPR Created
981223 JPR Event concept changed
990125 JPR EndParser updated
990211 JPR Corrections
990212 JPR Attribute handling corrected
990312 JPR Major changes. Handles the WML-specific parts
of the parsing.
990316 JPR Function WML_ModifyParse added.
990317 JPR Corrections
990329 JPR WAP 1.1
990330 JPR Memory leak removed
990414 JPR Corrections
990422 JPR Support for LITERALS
990512 JPR Corrections and extended error handling
990526 JPR Paragraph updates
990602 JPR LITERAL Correction
991011 JPR Correction in function WML_IsPEmptyInternal
991028 JPR WTA specific parts added
991206 JPR Changes to support new generic WBXML-decoder
991208 JPR Minor corrections
991223 JPR WML_CheckPublicID updated
000104 JPR Support for xml:space added
000131 JPR Correction in WML_LiteralAttributeToToken
000201 JPR Correction in WML_StoreAttributeValue and
WML_LiteralAttributeToToken
000204 JPR Correction in function WML_ModifyParse
000225 JPR Call of function WML_SetXmlSpace updated
000808 JPR Updated to support WTA-WML (WTA 1.2.1)
000811 JPR Addition of cache-control and new public identifiers
010119 NKE Updated WML_ModifyParse for the new decoder in wbxmldec.c.
010126 NKE Changed definition of WML_ModifyParse. Added new
functionality to WML_ModifyParse to be able to handle
complete wml documents and not as before only cards.
This functionality has ben moved from
wmlif.c/WML_ParseNextElement().
010305 JPR WTA-WML supported in function WML_CheckPublicID
==========================================================================*/
#include "wmlparse.h"
#include "wmltoken.h"
#include "wbxmldec.h"
#include "wbxmlelm.h"
#include "wmlevent.h"
#include "wmlelm.h"
/* WTA specific */
#ifdef CONFIG_WTA
#include "tapimmi.h"
#endif
/*
Examines if a p element is insignificant, i.e.,
NULL, empty, or only white space. Variables
(extensions) are considered significant.
*/
BOOL WML_IsPEmptyInternal (pDECSTR pDecStr, pELEMENTTYPE pPElement)
{
pELEMENTTYPE pContent=NULL;
WCHAR* pwchText=NULL;
WCHAR iEntity;
if (pPElement==NULL)
{
/* NO ELEMENT - EMPTY (?) */
return TRUE;
}
/* Get p content */
pContent=WML_GetContent(pPElement);
while (pContent!=NULL)
{
if (pContent->iType==Type_Inline_Text)
{
/* Inline text found, check if only white space */
pwchText=((pI_TEXTELEMENT)(pContent))->pwchTextData;
if (!WML_CheckIfOnlyWhiteSpace (pwchText))
{
/* Not only white space found */
return FALSE;
}
}
else if (pContent->iType==Type_Table_Text)
{
/* Table text found, check if only white space */
pwchText=WBXML_GetStrTabVal(pDecStr,
((pT_TEXTELEMENT)(pContent))->iTableRef);
if (!WML_CheckIfOnlyWhiteSpace (pwchText))
{
/* Not only white space found */
return FALSE;
}
}
else if (pContent->iType==Type_Entity)
{
/* Check if white space entity */
iEntity=(WCHAR) (((pENTITY)(pContent))->iEntity);
if (!((iEntity==(WCHAR)'\x20')||(iEntity==(WCHAR)'\x9')||
(iEntity==(WCHAR)'\xD')||(iEntity==(WCHAR)'\xA')))
{
/* Not white space */
return FALSE;
}
}
else
{
/* Other element found, return FALSE
(p element not empty) */
return FALSE;
}
/* Get next content */
pContent=pContent->pNextElement;
}
/* p element is empty */
return TRUE;
}
/*========================================================================
WML_ModifyParse
==========================================================================
NOTE: use WBXML_DeleteCurrentElement instead of XML_DeleteElement!
*/
void WML_ModifyParse (pDECSTR decodeStruct)
{
pELEMENTTYPE current = decodeStruct->currentElement;
pELEMENTTYPE parent = decodeStruct->parentElement;
if (current == NULL)
return;
switch (current->iType) {
case Type_P:
/* Check if p is empty (Static check) */
if (WML_IsPEmptyInternal(decodeStruct,current))
/* Remove p */
WBXML_DeleteCurrentElement(decodeStruct);
else {
/* Keep p and update current Wrap-mode */
if (((pPELEMENT) current)->iMode == P_Unknown)
((pPELEMENT) current)->iMode = ((UA*) decodeStruct->pAppSpec)->iCurrentWrapMode;
((UA*) decodeStruct->pAppSpec)->iCurrentWrapMode = ((pPELEMENT) current)->iMode;
}
break;
case Type_ONEVENT:
if (parent!=NULL) {
/* Only valid events are ONENTERFORWARD, ONENTERBACKWARD,
ONTIMER or ONCLICK. All other should be ignored. For
CARD and TEMPLATE the first three are valid and for
OPTION, the ONCLICK event is valid. */
/* If WTA is enabled, other events are valid in the CARD
and TEMPLATE as well. */
if (parent->iType == Type_OPTION) {
/* Check if the type is legal for OPTION. */
if ( ((pONEVENTELEMENT) current)->iEventType == DEF_TYPE_ONCLICK) {
/* Remove conflicting task - implies non-fatal error */
XML_DeleteElement(&(((pOPTIONELEMENT) parent)->pOnpick) ,decodeStruct);
/* Move the Action to "attribute level" */
((pOPTIONELEMENT) parent)->pOnpick = ((pONEVENTELEMENT) current)->pContent;
/* Remove the pointer to the task to allow the
use of DeleteElement without deleting the task. */
((pONEVENTELEMENT) current)->pContent = NULL;
break;
}
}
else if (((parent->iType == Type_CARD) || (parent->iType == Type_TEMPLATE)))
{
/* Check if the type is legal for CARD or TEMPLATE. */
if ((((pONEVENTELEMENT) current)->iEventType == DEF_TYPE_ONTIMER) ||
(((pONEVENTELEMENT) current)->iEventType == DEF_TYPE_ONENTERFORWARD) ||
(((pONEVENTELEMENT) current)->iEventType == DEF_TYPE_ONENTERBACKWARD)) {
/* The event is legal. Add event to the parent (CARD or TEMPLATE). */
WML_AddToEventTable(parent, (((pONEVENTELEMENT) current)->iEventType),
(((pONEVENTELEMENT)(current))->pContent));
break;
}
/* Check if WTA event (only if WTA is enabled AND the current user
agent is a WTA user agent) */
#ifdef CONFIG_WTA
if (((UA*) decodeStruct->pAppSpec)->iUserAgentMode == User_Agent_WTA) {
/* Allow WTA events as well Check if WTA event.
The following if-statement checks if the event is within the
legal boundaries for the current configuration.
*/
if (((((pONEVENTELEMENT) current)->iEventType >= WTAEvent_cc_ic) &&
(((pONEVENTELEMENT) current)->iEventType <= WTAEvent_ms_ns))
/* GSM Specific */
#ifdef CONFIG_WTAI_GSM
|| ((((pONEVENTELEMENT) current)->iEventType >= WTAEvent_gsm_ru) &&
(((pONEVENTELEMENT) current)->iEventType <= WTAEvent_gsm_ca))
#endif
/* PDC Specific */
#ifdef CONFIG_WTAI_PDC
/* No events defined */
#endif
/* IS-136 Specific */
#ifdef CONFIG_WTAI_IS_136
|| ((((pONEVENTELEMENT) current)->iEventType >= WTAEvent_is136_ia) &&
(((pONEVENTELEMENT) current)->iEventType <= WTAEvent_is136_if))
#endif
) {
/* The event is legal. Add event to the parent (CARD or TEMPLATE). */
WML_AddToEventTable(parent, (((pONEVENTELEMENT) current)->iEventType),
(((pONEVENTELEMENT) current)->pContent));
break;
}
}
#endif
}
}
/* ONEVENT type not legal - remove element */
WBXML_DeleteCurrentElement(decodeStruct);
break;
case Type_TEMPLATE:
/* Move the event table from the TEMPLATE element
to the event table in the User Agent. */
((UA*) decodeStruct->pAppSpec)->pTemplateEvents = ((pTEMPLATEELEMENT) current)->pEventTab;
break;
case Type_CARD:
((UA*) decodeStruct->pAppSpec)->iCurrentWrapMode = P_Wrap;
break;
case Type_UNKNOWN:
parent = ((pUNKNOWNELEMENT) current)->pContent;
((pUNKNOWNELEMENT) current)->pContent = NULL;
WBXML_DeleteCurrentElement(decodeStruct);
WBXML_AddElement(decodeStruct, parent);
break;
case Type_WML:
{
pELEMENTTYPE saveParent = parent;
pELEMENTTYPE saveCurrent = current;
decodeStruct->parentElement = current;
current = ((pWMLELEMENT) current)->pContent;
while (current != NULL) {
if (current->iType != Type_CARD &&
current->iType != Type_HEAD &&
current->iType != Type_TEMPLATE) {
decodeStruct->currentElement = current;
current = current->pNextElement;
WBXML_DeleteCurrentElement(decodeStruct);
decodeStruct->iDecodeResult |= WBXML_Warning_IllegalElement;
} else
current = current->pNextElement;
}
decodeStruct->currentElement = saveCurrent;
decodeStruct->parentElement = saveParent;
}
break;
}
}
/*========================================================================
WML_StoreAttributeValue
==========================================================================*/
BOOL WML_StoreAttributeValue (pDECSTR pDecStr, pELEMENTTYPE pElement,
UINT16 iAttribute, pELEMENTTYPE* ppAttrVal)
{
BOOL fWTA=FALSE;
BOOL fResult=TRUE;
#ifdef CONFIG_WTA
/* Set the fWTA to TRUE if the user agent is WTA enabled,
FALSE otherwise. This is used when the WML_SetType
function is called. */
if (((UA*)(pDecStr->pAppSpec))->iUserAgentMode==User_Agent_WTA)
{
fWTA=TRUE;
}
#endif
if (pElement!=NULL)
{
/* Store attribute value */
switch (iAttribute)
{
case ATTRST_accept_charset:
fResult=WML_SetAccChar(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_accesskey:
fResult=WML_SetAccesskey(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_align:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,DEF_TYPE_STRING);
break;
case ATTRST_align_bottom:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_BOTTOM);
break;
case ATTRST_align_center:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_CENTER);
break;
case ATTRST_align_left:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_LEFT);
break;
case ATTRST_align_middle:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_MIDDLE);
break;
case ATTRST_align_right:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_RIGHT);
break;
case ATTRST_align_top:
fResult=WML_SetAlign(pDecStr,pElement,ppAttrVal,ALIGN_TOP);
break;
case ATTRST_alt:
fResult=WML_SetAlt(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_cache_control:
fResult=WML_SetCacheControl(pDecStr,pElement,ppAttrVal,Cache_nocache);
break;
case ATTRST_class:
/* Not used - delete */
XML_DeleteElementList(ppAttrVal,pDecStr);
break;
case ATTRST_columns:
fResult=WML_SetColumns(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_content:
fResult=WML_SetContent(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_content_wmlc_charset:
XML_AddHeadString(ppAttrVal,"application/vnd.wap.wmlc;charset=",pDecStr);
fResult=WML_SetContent(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_domain:
fResult=WML_SetDomain(pDecStr,pElement,ppAttrVal);
break;
case ATTRST_emptyok_false:
fResult=WML_SetEmptyOK(pDecStr,pElement,ppAttrVal,FALSE);
break;
case ATTRST_emptyok_true:
fResult=WML_SetEmptyOK(pDecStr,pElement,ppAttrVal,TRUE);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -