📄 wml_uafn.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.
*/
#ifndef WML_UAFN_C
#define WML_UAFN_C
#include "wml_uafn.h"
#include "wmldef.h"
#include "wmltoken.h"
#include "wbxmldef.h"
#include "wbxmldec.h"
#include "wmlif.h"
#include "wmlelm.h"
#include "url.h"
#include "headdef.h"
#include "hdrutil.h"
#include "aapimmi.h"
#include "aapiwta.h"
#include "trnscode.h"
#include "history.h"
#include "wipprdct.h"
#ifdef USE_KSC5601
#include "HCodeCnvt.h"
#endif
/* -------------------------------- internal defines ---------------------------------------- */
void CreatePostString(UA* pUserAgent, GOELEMENT* pGoElement, INT16 iCharEnc, BYTE** ppString, UINT16* piDataLen );
void CreateNavigationData( UA* pUserAgent, GOELEMENT* pGoElement, HISTORYITEM** ppHistoryItem, BYTE** ppTargetURL );
void CreatePostBody(UA* pUserAgent, GOELEMENT* pGoElement, INT16 iCharEnc, BYTE** pbData, UINT16* piDataLen);
WCHAR* getLang(void* pElement, UINT16 iType);
#ifdef USE_KSC5601
BYTE* Unicode2byteSpecialKSCConvert(WCHAR* pURL);
#endif
typedef struct tPOSTSTRINGPART
{
void* pData;
struct tPOSTSTRINGPART *pNextField;
} POSTSTRINGPART, *pPOSTSTRINGPART;
typedef struct
{
UINT8 iUrlID;
UINT8 iSendMode;
} CONTENTREQUESTSTRUCT,*pCONTENTREQUESTSTRUCT;
/*------------------------------Content UA functionality --------------------------------------*/
void SDL_StoreContentRequest( void* pContentRequestList,int iUrlID,int iTID, int iSendMode)
{
CONTENTREQUESTSTRUCT* pCRStruct;
/* aspn 001101
int iDummy;
*/
pCRStruct = NEWSTRUCT(CONTENTREQUESTSTRUCT);
if (pCRStruct)
{
pCRStruct->iUrlID=(UINT8)iUrlID;
pCRStruct->iSendMode=(UINT8)iSendMode;
/* aspn 001101
iDummy=SDL_AddElementLast(pContentRequestList,iTID, pCRStruct);
*/
SDL_AddElementLast(pContentRequestList,iTID, pCRStruct);
}
}
int SDL_GetContentRequestUrlID(void* pCRStruct)
{
return ((CONTENTREQUESTSTRUCT*)pCRStruct)->iUrlID;
}
int SDL_GetContentRequestTID( void* pContentRequestList,int iUrlID )
{
void* pvListElement = NULL;
void* pvElementContent = NULL;
CONTENTREQUESTSTRUCT* pCRStruct = NULL;
if( pContentRequestList != NULL ){
pvListElement = SDL_GetNextListElement( pContentRequestList, NULL );
while( pvListElement != NULL ){
pvElementContent = SDL_GetListElementContent( pvListElement );
if( pvElementContent != NULL ){
pCRStruct = (CONTENTREQUESTSTRUCT*)pvElementContent;
if( pCRStruct != NULL && pCRStruct->iUrlID == iUrlID ){
return SDL_GetListElementID( pvListElement );
}
}
pvListElement = SDL_GetNextListElement( pContentRequestList, pvListElement );
}
}
return 0;
}
int SDL_GetContentSendMode( void* pContentRequestList,int iTID )
{
void* pvListElement = NULL;
CONTENTREQUESTSTRUCT* pCRStruct = NULL;
if( pContentRequestList != NULL ){
pvListElement = SDL_SearchListElement( pContentRequestList, iTID, NULL);
if( pvListElement != NULL ){
pvListElement = SDL_GetListElementContent( pvListElement );
if( pvListElement != NULL ){
pCRStruct = (CONTENTREQUESTSTRUCT*)pvListElement;
return pCRStruct->iSendMode;
}
}
}
return 0;
}
/*------------------------------General WML/WTA UA funct.---------------------------------------*/
/*---------------------------------------------
Create a new user agent.
Input: The view associated with the UA
Output: Pointer to the User Agent (ELEMENT),
NULL if no memory
----------------------------------------------*/
void* SDL_CreateUA(int ViewID)
{
UA* pUser=NULL;
pUser = WML_CreateUserAgent();
if (pUser !=NULL)
{
pUser->fUserLoadMode = FALSE;
pUser->iViewID = (INT8)ViewID;
pUser->pbURLBase = NULL;
}
return (void*)pUser;
}
/*---------------------------------------------
Removes the current deck and all its structures,
the variables and context are kept though.
Input: Pointer to the User Agent
Output: -
----------------------------------------------*/
void SDL_CleanUpDeck(void*pUser)
{
WML_EmptyDECK((UA*)pUser);
}
/*---------------------------------------------
clears the current UA context
Input: Pointer to the User Agent
Output: -
----------------------------------------------*/
void SDL_ClearContext(void* pUserAgent)
{
UA* pUser;
pUser = (UA*)pUserAgent;
WML_EmptyHistoryList(pUser);
WML_EmptyVarTable(pUser);
/* SDL_Free( & (pUser->pbURLBase) ); */
}
/*---------------------------------------------
A complete removal of all data associated with
this particular User Agent. To be used when a
complete shutdown is performed.
----------------------------------------------*/
void SDL_CleanUpUserAgent(void** ppUserAgent)
{
UA** ppUser;
ppUser = (UA**)ppUserAgent;
SDL_ClearContext(*ppUser);
SDL_CleanUpDeck(*ppUser);
WML_DeleteUserAgent (ppUser);
}
/*----------------------------------- Parser functionality -----------------------------------------*/
/*------------------------------------------------------------
initiate parsing returns a pointer to the allocated buffer
-------------------------------------------------------------*/
BOOL SDL_ParseData(void *pUserAgent, void* pData, int iBufLen, void* pResponseInfo)
{
UA* pUser=NULL;
UINT8 iPIVersion=1; /* 1=unknown */
INT16 iCharset=IANA_CHARSET_INVALID;
BYTE iContentTypeByte=0;
pUser = (UA*)pUserAgent;
/* use the old raw data to parse */
if (pData==NULL)
{
#ifdef TASKFAILURE_REPARSE_RAWDATA
iPIVersion = pUser->iOldPIVersion;
iContentTypeByte = pUser->iOldContentTypeByte;
iCharset = pUser->iOldCharset;
iBufLen = pUser->iOldRawWMLDeckDataLen;
pData = pUser->pOldRawWMLDeckData;
/* to enable the reparse to be performed several times */
pUser->iTempPIVersion = pUser->iOldPIVersion;
pUser->iTempContentTypeByte = pUser->iOldContentTypeByte;
pUser->iTempCharset = pUser->iOldCharset;
pUser->iTempRawWMLDeckDataLen = pUser->iOldRawWMLDeckDataLen;
DEALLOC(&pUser->pTempRawWMLDeckData);
pUser->pTempRawWMLDeckData = pUser->pOldRawWMLDeckData;
if (pData==NULL)
return 0;
#else
return 0;
#endif
}
else
{
iCharset = ((CONTENTINFOSTRUCT*)pResponseInfo)->iIANACharID;
iPIVersion = ((CONTENTINFOSTRUCT*)pResponseInfo)->iPIVersion;
iContentTypeByte = ((CONTENTINFOSTRUCT*)pResponseInfo)->iContentTypeAsInt;
#ifdef TASKFAILURE_REPARSE_RAWDATA
pUser->iTempPIVersion = iPIVersion;
pUser->iTempContentTypeByte =iContentTypeByte;
pUser->iTempCharset =iCharset;
DEALLOC( & pUser->pTempRawWMLDeckData);
pUser->pTempRawWMLDeckData = (BYTE*)pData;
pUser->iTempRawWMLDeckDataLen = iBufLen;
#endif
}
#ifdef WAE_DEBUG
PrintChar("------Parsing--------------");
PrintChar("Size:");
PrintInt(iBufLen);
PrintChar("character encoding:");
#endif
pUser->iTextEncodFormat = iCharset;
return WML_StartParser(pUser,(BYTE*)pData,(UINT32)iBufLen,iContentTypeByte,iPIVersion);
}
/*---------------------------------------------
parse next card
returns FALSE=more, TRUE=finished ok
-----------------------------------------------*/
int SDL_ParseNext(void *pUserAgent)
{
BOOL finished;
((UA*) pUserAgent)->pDeck = WBXML_Decode(((UA*) pUserAgent)->pDecStr, &finished);
return finished;
}
/*---------------------------------------------
finalise parse returns FALSE=not ok, TRUE=finished ok
-----------------------------------------------*/
int SDL_EndParse(void *pUserAgent)
{
UA* pUser=NULL;
BOOL fRetVal;
UINT32 iErrors=0;
pUser = (UA*)pUserAgent;
fRetVal = WML_EndParser((UA*)pUserAgent);
if (fRetVal)
{
/* all was ok then accept raw data as old fallbackdata */
#ifdef TASKFAILURE_REPARSE_RAWDATA
pUser->iOldPIVersion = pUser->iTempPIVersion;
pUser->iTempPIVersion =0;
pUser->iOldContentTypeByte = pUser->iTempContentTypeByte;
pUser->iTempContentTypeByte =0;
pUser->iOldCharset = pUser->iTempCharset;
pUser->iTempCharset=0;
if (pUser->pOldRawWMLDeckData != pUser->pTempRawWMLDeckData)
{
DEALLOC( & pUser->pOldRawWMLDeckData);
}
pUser->pOldRawWMLDeckData = pUser->pTempRawWMLDeckData;
pUser->pTempRawWMLDeckData=NULL;
pUser->iOldRawWMLDeckDataLen = pUser->iTempRawWMLDeckDataLen;
pUser->iTempRawWMLDeckDataLen=0;
#endif
}
iErrors=pUser->pDecStr->iDecodeResult;
/* Report warnings */
if ( iErrors & WBXML_Warning_UnknownToken )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WML_UNKNOWN_TOKEN, ERRTYPE_INFORMATION);
}
if ( iErrors & WBXML_Warning_Version )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WBXML_CONTENT_VERSION_WARNING, ERRTYPE_INFORMATION);
}
if ( iErrors & WBXML_Warning_UnknownCharset )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WML_CONTENT_CHARSET_NOT_SUPPORTED, ERRTYPE_INFORMATION);
}
/* Report errors */
if ( iErrors & WBXML_Error_DataStream )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WML_INSTREAM_FAULT, ERRTYPE_INFORMATION);
}
if ( iErrors & WBXML_Error_CharsetEncoding )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WML_CONTENT_CHARSET_ERROR, ERRTYPE_INFORMATION);
}
if ( iErrors & WBXML_Error_PublicID )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WBXML_CONTENT_PUBLIC_ID_ERROR, ERRTYPE_INFORMATION);
}
/* WBXML_Error_OutOfMemory, WBXML_Error_StringTable, WBXML_Error_MbuintEncoding,
WBXML_Error_Encoding, or WBXML_Error_Unknown */
if ( iErrors & 0xAD0000 )
{
CLNTa_error (pUser->iViewID, ERR_WAE_WML_WML_ERROR, ERRTYPE_INFORMATION);
}
return fRetVal;
}
void SDL_AbortParsing(void *pUserAgent)
{
#ifdef TASKFAILURE_REPARSE_RAWDATA
UA* pUser=NULL;
pUser = (UA*)pUserAgent;
pUser->iTempPIVersion =0;
pUser->iTempContentTypeByte =0;
pUser->iTempCharset=0;
if (pUser->pOldRawWMLDeckData != pUser->pTempRawWMLDeckData)
{
DEALLOC( & pUser->pTempRawWMLDeckData);
}
else
{
pUser->pTempRawWMLDeckData=NULL;
}
pUser->iTempRawWMLDeckDataLen=0;
#endif
WML_AbortParser ((UA*)pUserAgent);
}
/*----------------------------------------- WML Element funct.---------------------------------------*/
/*---------------------------------------------
Checks the deck for HEAD elements which may contain
access restrictions
Input: User Agent
Output: TRUE = accessfailure, FALSE = no accessfailure
----------------------------------------------*/
int SDL_CheckAccess(void* pUserAgent, void* pResponseURL, int iFromCard)
{
ELEMENTTYPE* pDeckPart=NULL;
ELEMENTTYPE* pHeadPart=NULL;
BYTE* pbDefaultDomain=NULL;
BYTE* pbBase=NULL;
UA* pUser=NULL;
BOOL fRes=FALSE;
pUser = (UA*)pUserAgent;
if (pUser->pDeck !=NULL && pUser->pDecStr !=NULL)
{
if ((pUser->pDeck)->iType==Type_WML )
{
pDeckPart = WML_GetContent(pUser->pDeck);
while (pDeckPart != NULL)
{
/* Search for HEAD element */
if (pDeckPart->iType==Type_HEAD)
{
pHeadPart = WML_GetContent(pDeckPart);
/* search for access elements */
while (pHeadPart!=NULL)
{
if (pHeadPart->iType==Type_ACCESS)
{
b_GetHost ((BYTE*)pResponseURL, & pbDefaultDomain);
pbBase = pUser->pbURLBase;
if (iFromCard==0) /* if it is a direct navigation, the base should be empty */
pbBase = NULL;
if (!WML_CheckAccessElement(pHeadPart, pbBase, pbDefaultDomain))
{
fRes = TRUE;
}
DEALLOC(&pbDefaultDomain);
}
pHeadPart = WML_GetNextElement(pHeadPart);
}
}
pDeckPart = WML_GetNextElement(pDeckPart);
}
}
}
return fRes;
}
/*---------------------------------------------
SDL_GetTimerValue: Used by SDL to get the appropriate
timer value for a certaion card.
Input:
Output:
----------------------------------------------*/
int SDL_GetTimerValue(void* pUser, void* pTimerElement)
{
return ((int)(WML_GetTimer ((UA*)pUser, (ELEMENTTYPE*)pTimerElement)));
}
/*---------------------------------------------
SDL_GetElementType: used from SDL to determine the
type of element.
Input: TheElement
Output: type - according to definitions.h
----------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -