📄 wmlif.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: wmlif.c
Source file for the interface between WAE and the WML-structure.
Includes function to initiate the parse of a WML-deck and using
the structure created during the parse.
Rev history:
980728 JPR Created
990208 JPR Corrections
990315 JPR Major changes. Handles the WML-specific parts
of the startup and closing down of the parser.
990316 JPR Variable handling moved here from WMLElm.h
990406 JPR Corrections
990409 JPR Access handling modified
990412 JPR Url.h used instead of Url_Lib.h
990413 JPR WML_HandleMMIAction corrected
990420 JPR WML_EndParser updated. Card/Deck-shadowing
on do elements corrected.
990421 JPR WML_UpdateAllSelect corrected. Now handles p
and fieldset.
990427 JPR Corrections in History functions
990517 JPR WML/WBXML Version handling updated and
extended error handling.
990528 JPR History functions updated. Paragraph updates
990106 JPR Navigation corrections (setvar element)
990610 JPR Trim text functions updated.
990709 JPR Store Timer function corrected.
990823 JPR Correction in WML_EndParserHelp
990826 JPR Function WML_NewContext added.
990827 JPR Correction in WML_ParseNextElement
991020 JPR WTA additions included
991109 JPR TR 173. Correction in WML_ParseNextElement
991124 JPR History functions moved to History.c
991208 JPR Changes to support new generic WBXML-decoder,
PARALLELL_PARSE_ENABLED removed.
000110 IPN Removed pVisitedHosts from WML_CreateUserAgent.
000111 JPR DeleteHostList function call removed.
000113 JPR Correction in WML_GetNextElement
000117 JPR Function WML_CreateUserAgent modified
000203 JPR WML_GetNextElement corrected
000209 JPR Correction in functions WML_GetAssembleLength and
WML_UpdateSelect
000808 JPR Updated to support WTA-WML (WTA 1.2.1). Correction in
Code page handling.
000810 JPR Default wrap mode added to card. Switch page corrected
000925 JPR Correction to support post with correct charset
010119 NKE Updated WML_StartParser and WML_ParseNextElement for
the new decoder in wbxmldec.c.
010125 NKE Updated WML_StartParser.
010516 IPN Changes in WML_GetString, new escape function.
Changes in WML_GetStringLength, new escape function.
==========================================================================*/
#include "confvars.h"
#include "cmmnrsrc.h"
#include "wmlparse.h"
#include "wmlif.h"
#include "hdrutil.h"
#include "url.h"
#include "waectype.h"
#include "history.h"
#include "wbxmldec.h"
#include "wbxmlelm.h"
#include "xml_conv.h"
#include "wmlevent.h"
/*========================================================================
WML_CreateUserAgent
==========================================================================*/
pUA WML_CreateUserAgent (void)
{
pUA pUser;
pUser=NEWSTRUCT(UA);
if (pUser!=NULL)
{
pUser->iUserAgentMode=User_Agent_WML;
pUser->pDeck=NULL;
pUser->pDecStr=NULL;
pUser->pbURLBase=NULL;
pUser->pEventVariables=NULL;
/* This attribute is shared with the template.
DO NOT DEALLOCATE when the user agent is
deleted. Handled when the TEMPLATE element
is deleted. */
pUser->pTemplateEvents=NULL;
pUser->iViewID=0;
pUser->fLockMMI=FALSE;
pUser->fUserInputMode=FALSE;
pUser->pHistoryList=NULL;
pUser->iElmInHistory=0;
pUser->iMaxElmInHistory=10;
pUser->pCurrentCard=NULL;
pUser->iCurrentWrapMode=P_Unknown;
pUser->pVARTABLE=NULL;
pUser->iTextEncodFormat=IANA_CHARSET_INVALID;
pUser->pWMLDeckData=NULL;
#ifdef TASKFAILURE_REPARSE_RAWDATA
pUser->iOldPIVersion=0;
pUser->iOldContentTypeByte=0;
pUser->iOldCharset=0;
pUser->pOldRawWMLDeckData = NULL;
pUser->iOldRawWMLDeckDataLen =0;
pUser->iTempPIVersion=0;
pUser->iTempContentTypeByte=0;
pUser->iTempCharset=0;
pUser->pTempRawWMLDeckData = NULL;
pUser->iTempRawWMLDeckDataLen =0;
#endif
}
return pUser;
}
/*========================================================================
WML_DeleteUserAgent
==========================================================================*/
void WML_DeleteUserAgent (pUA *ppUser)
{
if (*ppUser!=NULL)
{
/* Delete variable table */
WML_EmptyVarTable (*ppUser);
/* Delete temporary variable list */
WML_DeleteEventVariables (*ppUser);
/* Delete deck */
WML_EmptyDECK(*ppUser);
/* Delete history */
WML_EmptyHistoryList(*ppUser);
/* Dealloc pbURLBase */
DEALLOC(&((*ppUser)->pbURLBase));
/* Delete Decode Struct if not already deleted. */
WBXML_DeleteWBXMLDecStr(&((*ppUser)->pDecStr));
#ifdef TASKFAILURE_REPARSE_RAWDATA
if( (*ppUser)->pOldRawWMLDeckData == (*ppUser)->pTempRawWMLDeckData ){
DEALLOC( & ((*ppUser)->pOldRawWMLDeckData) );
(*ppUser)->pTempRawWMLDeckData = NULL;
}
else{
DEALLOC( & ((*ppUser)->pOldRawWMLDeckData) );
DEALLOC( & ((*ppUser)->pTempRawWMLDeckData) );
}
#endif
DEALLOC (ppUser);
}
}
/*========================================================================
WML_StartParser
==========================================================================*/
BOOL WML_StartParser (pUA pUser, BYTE *pbStream, UINT32 iNbrOfBytes,
BYTE bContentType, UINT8 iContentLevel)
{
pWBXMLDECODESTR pDecStr=NULL;
if (pUser!=NULL)
{
pUser->iCurrentWrapMode = P_Wrap;
/* Check if decode struct exists */
if (pUser->pDecStr!=NULL)
{
/* Remove old deck */
WML_EmptyDECK(pUser);
/* Clear string table */
WBXML_DelStrTab(pUser->pDecStr);
/* Use old decode struct */
pDecStr=pUser->pDecStr;
}
else
{
/* Create tWBXMLDECODESTR and init the attributes */
pDecStr=WBXML_CreateWBXMLDecStr();
if (pDecStr!=NULL)
{
/* Set the function pointers */
pDecStr->DTD_CreateElement = WML_CreateElement;
pDecStr->DTD_DeleteElement = WML_DeleteElement;
pDecStr->DTD_ValidContent = WML_ValidContent;
pDecStr->DTD_GetContent = WML_GetContent;
pDecStr->DTD_AppSpecParseMod = WML_ModifyParse;
pDecStr->DTD_StoreAttributeValue = WML_StoreAttributeValue;
pDecStr->DTD_GetAttributeValue = WML_GetAttributeValue;
pDecStr->DTD_LiteralAttributeToToken = WML_LiteralAttributeToToken;
pDecStr->DTD_LiteralTagToToken = WML_LiteralTagToToken;
pDecStr->DTD_CheckPublicID = WML_CheckPublicID;
}
}
if (pDecStr!=NULL)
{
/* Init values */
pDecStr->pbCurByte=pbStream;
pDecStr->pbEnd=pbStream+iNbrOfBytes;
pDecStr->iCharset=pUser->iTextEncodFormat;
pDecStr->iContentLevel=iContentLevel;
pDecStr->bContentType=bContentType;
pDecStr->iDecodeResult=0;
pDecStr->pAppSpec=NULL;
pDecStr->iTagCodePage=0;
pDecStr->iAttrCodePage=0;
pDecStr->iVersion=0;
pDecStr->pStrTab=NULL;
WBXML_InitDecode(pDecStr, FALSE);
/* Connect the structs */
pDecStr->pAppSpec=pUser;
pUser->pDecStr=pDecStr;
if (WBXML_DecodeProlog(pDecStr))
{
/* To support post with correct charset */
pUser->iTextEncodFormat = pDecStr->iCharset;
return TRUE;
}
}
}
return FALSE;
}
/*========================================================================
WML_EndParser
==========================================================================*/
void WML_FixTemplateDo (pUA pUser)
{
pELEMENTTYPE pTemplate=NULL;
pELEMENTTYPE pCard=NULL;
pELEMENTTYPE pBack=NULL;
pELEMENTTYPE pCardDO=NULL;
pELEMENTTYPE pContent=NULL;
WCHAR *pchTName=NULL;
WCHAR *pchCName=NULL;
BOOL fCont=TRUE;
BOOL fOverridden=FALSE;
/* Get TEMPLATE */
pContent=WML_GetContent(pUser->pDeck);
while ((pContent!=NULL)&&(fCont))
{
if (pContent->iType==Type_TEMPLATE)
{
pTemplate=pContent;
fCont=FALSE;
}
else
{
pContent=pContent->pNextElement;
}
}
if (pTemplate==NULL)
{
return;
}
/* TEMPLATE found */
/* Check if the TEMPLATE contains any DO element */
pContent=WML_GetContent(pTemplate);
fCont=FALSE;
while ((pContent!=NULL)&&(!fCont))
{
if (pContent->iType==Type_DO)
{
fCont=TRUE;
}
else
{
pContent=pContent->pNextElement;
}
}
/* fCont is TRUE if the TEMPLATE contains
at least one DO element */
if (fCont)
{
pCard=WML_GetContent(pUser->pDeck);
/* Add TEMPLATE DO for every CARD */
while (pCard!=NULL)
{
if (pCard->iType==Type_CARD)
{
/* CARD found. Examine content of TEMPLATE. Add
the DO elements that exist on TEMPLATE
level and are not overridden on the CARD. */
pContent=WML_GetContent(pTemplate);
/* Find all DO on TEMPLATE */
while (pContent!=NULL)
{
if (pContent->iType==Type_DO)
{
/* TEMPLATE DO found - Get Name */
pchTName=((DOELEMENT*)(pContent))->pchName;
if (pchTName==NULL)
{
/* Set Name as Type */
pchTName=((DOELEMENT*)(pContent))->pchType;
}
if (pchTName!=NULL)
{
/* Get CARD DO */
pCardDO=WML_GetContent(pCard);
fOverridden=FALSE;
pBack=NULL;
/* Compare with all CARD-level DO elements */
while ((pCardDO!=NULL)&&(!fOverridden))
{
if (pCardDO->iType==Type_DO)
{
/* Card DO found - Get Card DO Name */
pchCName=((DOELEMENT*)(pCardDO))->pchName;
if (pchCName==NULL)
{
/* Set Name as Card DO Type */
pchTName=((DOELEMENT*)(pCardDO))->pchType;
}
if (pchCName!=NULL)
{
/* Compare the names */
if (COMPARESTRING(pchTName,pchCName)==0)
{
/* Equal - overridden by the card */
fOverridden=TRUE;
}
}
pCardDO=pCardDO->pNextElement;
}
/* Wap 1.1 specific addition
(Check p contents) */
else if (pCardDO->iType==Type_P)
{
/* Pointer back to this level */
pBack=pCardDO;
pCardDO=WML_GetContent(pCardDO);
}
/* Get next possible DO */
else
{
pCardDO=pCardDO->pNextElement;
if (pCardDO==NULL)
{
pCardDO=pBack;
pBack=NULL;
if (pCardDO!=NULL)
{
pCardDO=pCardDO->pNextElement;
}
}
}
}
/* If the TEMPLATE DO is not overridden - add to card. */
if (!fOverridden)
{
/* Add to card */
WML_AddTemplateDO(pCard,pContent);
}
}
}
/* Get next TEMPLATE content */
pContent=pContent->pNextElement;
}
}
/* Get next card */
pCard=pCard->pNextElement;
}
}
}
BOOL WML_EndParser (pUA pUser)
{
BOOL fDecodeOK=FALSE;
if (pUser==NULL)
{
return FALSE;
}
/* Check if the parse was ok. */
if (pUser->pDecStr!=NULL)
{
fDecodeOK=(pUser->pDecStr->iDecodeResult<=WBXML_FatalError);
}
if (!fDecodeOK)
{
/* Parse not ok - delete deck */
XML_DeleteElement (&(pUser->pDeck),pUser->pDecStr);
/* Clear string table */
WBXML_DelStrTab(pUser->pDecStr);
return FALSE;
}
/* Decoding OK, Fix TEMPLATE DO */
WML_FixTemplateDo (pUser);
return TRUE;
}
/*========================================================================
WML_AbortParser
==========================================================================*/
void WML_AbortParser (pUA pUser)
{
/* Set unknown error and call WML_EndParser */
if (pUser!=NULL)
{
if (pUser->pDecStr!=NULL)
{
/* Set unknown error */
pUser->pDecStr->iDecodeResult|=WBXML_Error_Unknown;
}
WML_EndParser (pUser);
}
}
/*========================================================================
WML_EmptyDECK
==========================================================================*/
void WML_EmptyDECK (pUA pUser)
{
if (pUser!=NULL)
{
XML_DeleteElement(&(pUser->pDeck),pUser->pDecStr);
pUser->pDeck=NULL;
/* Remove the eventtable. (Deleted in TEMPLATE
element, set to NULL) */
pUser->pTemplateEvents=NULL;
}
}
/*========================================================================
VARIABLE TABLE FUNCTIONS
=========================================================================*/
/*========================================================================
WML_SetVariable
==========================================================================*/
BOOL WML_SetVariable (pUA pUser, WCHAR *pchName, WCHAR *pchValue, BOOL fWTA)
{
pVARTABELM pVARTABTemp=pUser->pVARTABLE;
pVARTABELM pVARTABTempPar=NULL;
WCHAR *pchTempValue;
if (pchName!=NULL)
{
/* Check if valid name */
if (WML_CheckVariableSyntax (pchName,fWTA))
{
/* Empty string with nullterm is equal to NULL */
if (pchValue!=NULL)
{
if (*pchValue==0)
{
pchValue=NULL;
}
}
/* Check if the variable already exists. */
while (pVARTABTemp!=NULL)
{
if (COMPARESTRING(pVARTABTemp->pchName,pchName)==0)
{
/* Var name exists - delete the old value
and add the new value */
/* Check new value */
if (pchValue!=NULL)
{
pchTempValue=CreateStringCopy(pchValue);
/* Check if value copied. */
if (pchTempValue!=NULL)
{
/* Change value */
DEALLOC(&(pVARTABTemp->pchValue));
pVARTABTemp->pchValue=pchTempValue;
return TRUE;
}
else
{
/* Could not change value */
return FALSE;
}
}
else
{
/* Remove variable from list */
DEALLOC(&(pVARTABTemp->pchName));
DEALLOC(&(pVARTABTemp->pchValue));
if (pVARTABTempPar==NULL)
{
pUser->pVARTABLE=pVARTABTemp->pNextVar;
}
else
{
pVARTABTempPar->pNextVar=pVARTABTemp->pNextVar;
}
DEALLOC(&pVARTABTemp);
return TRUE;
}
}
if (pVARTABTempPar==NULL)
{
pVARTABTempPar=pUser->pVARTABLE;
}
else
{
pVARTABTempPar=pVARTABTemp;
}
pVARTABTemp=pVARTABTemp->pNextVar;
}
/* Create new variable and add to variable table. */
pVARTABTemp=NEWSTRUCT(VARTABELM);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -