📄 wmlif.c
字号:
if (pVARTABTemp!=NULL)
{
pVARTABTemp->pchName=CreateStringCopy(pchName);
pVARTABTemp->pchValue=CreateStringCopy(pchValue);
pVARTABTemp->pNextVar=NULL;
/* Check if really created. */
if (pVARTABTemp->pchName!=NULL)
{
/* Check value. */
if (pchValue!=NULL)
{
if (pVARTABTemp->pchValue!=NULL)
{
/* Add to list. */
if (pUser->pVARTABLE==NULL)
{
pUser->pVARTABLE=pVARTABTemp;
}
else
{
pVARTABTempPar->pNextVar=pVARTABTemp;
}
return TRUE;
}
}
}
/* Error - Delete element. */
DEALLOC(&pVARTABTemp->pchName);
DEALLOC(&pVARTABTemp->pchValue);
DEALLOC(&pVARTABTemp);
}
}
else
{
/* Syntax error */
return FALSE;
}
}
/* ERROR - return FALSE */
return FALSE;
}
/*========================================================================
WML_GetVariable
==========================================================================*/
WCHAR *WML_GetVariable (pUA pUser, WCHAR *pchName)
{
pVARTABELM pVARTABTemp=pUser->pVARTABLE;
if (pchName!=NULL)
{
while (pVARTABTemp!=NULL)
{
if (COMPARESTRING(pchName,pVARTABTemp->pchName)==0)
{
return CreateStringCopy(pVARTABTemp->pchValue);
}
pVARTABTemp=pVARTABTemp->pNextVar;
}
}
return NULL;
}
/*========================================================================
WML_EmptyVarTable
==========================================================================*/
void WML_EmptyVarTable (pUA pUser)
{
pVARTABELM pVARTABLE;
pVARTABELM pVARTABLETemp;
pVARTABLETemp=pUser->pVARTABLE;
while (pVARTABLETemp!=NULL)
{
pVARTABLE=pVARTABLETemp;
DEALLOC(&(pVARTABLE->pchName));
DEALLOC(&(pVARTABLE->pchValue));
pVARTABLETemp=pVARTABLETemp->pNextVar;
DEALLOC(&pVARTABLE);
}
pUser->pVARTABLE=NULL;
}
/*========================================================================
WML_DeleteEventVariables
==========================================================================*/
void WML_DeleteEventVariables (pUA pUser)
{
pVARTABELM pVarList=NULL;
pVARTABELM pTempVar=NULL;
/* ASSERT: pUser!=NULL
*/
pVarList=pUser->pEventVariables;
while (pVarList!=NULL)
{
pTempVar=pVarList;
pVarList=pVarList->pNextVar;
/* Remove element */
DEALLOC(&pTempVar->pchName);
DEALLOC(&pTempVar->pchValue);
DEALLOC(&pTempVar);
}
pUser->pEventVariables=NULL;
}
/*========================================================================
WML_AddEventVariablesToContext
==========================================================================*/
void WML_AddEventVariablesToContext (pUA pUser)
{
pVARTABELM pTempVar=NULL;
/* ASSERT: pUser!=NULL
*/
pTempVar=pUser->pEventVariables;
while (pTempVar!=NULL)
{
/* Set variable */
WML_SetVariable (pUser, pTempVar->pchName, pTempVar->pchValue,
(pUser->iUserAgentMode==User_Agent_WTA));
pTempVar=pTempVar->pNextVar;
}
/* Delete list */
WML_DeleteEventVariables (pUser);
}
/*========================================================================
WML_CheckVariableSyntax
==========================================================================*/
/* ( "_" | alpha ) *[ "_" | alpha | digit )
if WTA is enabled:
( "_" | alpha | digit ) *[ "_" | alpha | digit )
*/
BOOL WML_CheckVariableSyntax (WCHAR *pchVariable, BOOL fWTA)
{
fWTA=fWTA;
if (pchVariable!=NULL)
{
if (*pchVariable!=0)
{
if ((*pchVariable==WC('_'))||
((*pchVariable < 0x100) && wae_isalpha(*pchVariable))
/* WTA specific */
#ifdef CONFIG_WTA
||
/* digit */
((fWTA)&&(*pchVariable < 0x100) && wae_isdigit(*pchVariable))
#endif
)
{
pchVariable++;
while (*pchVariable!=0)
{
if (((*pchVariable < 0x100) && wae_isalpha(*pchVariable))||
((*pchVariable < 0x100) && wae_isdigit(*pchVariable))||
(*pchVariable==WC('_')))
{
pchVariable++;
}
else
{
return FALSE;
}
}
/* Has at least one char, and loop OK */
return TRUE;
}
}
}
return FALSE;
}
/*========================================================================
SELECT ELEMENT FUNCTIONS
=========================================================================*/
/* Help function for CalculateResultLength */
UINT16 WML_GetNumberLength (UINT16 iNumber)
{
UINT16 iResult=1;
while (iNumber>=10)
{
iNumber/=10;
iResult++;
}
return iResult;
}
/* Calculates the length of the string to be constructed
when making a ';'-separated list from a NUMBERSTRUCT. */
UINT16 WML_CalculateResultLength (pNUMBERSTRUCT pOptions)
{
UINT16 iResult=0;
while (pOptions!=NULL)
{
iResult+=WML_GetNumberLength(pOptions->iIndex);
/* Add space for ';' */
iResult++;
pOptions=pOptions->pNext;
}
if (iResult>0)
{
/* Remove one ';' */
iResult--;
}
return iResult;
}
/* Help function for ConvertNumber2String */
void WML_SetOneNumber (UINT16 iNumber, WCHAR **ppchString)
{
UINT16 iDiv=0;
UINT16 iMod=0;
if (iNumber>0)
{
iDiv=(UINT16)(iNumber/10);
iMod=(UINT16)(iNumber%10);
WML_SetOneNumber(iDiv,ppchString);
**ppchString=(UINT16)(WC('1')+iMod-1);
(*ppchString)++;
}
}
/* Assembles the numbers in the NUMBERSTRUCT to a ';'-
separated string. (E.g 1 5 13 -> "1;5;13") */
void WML_ConvertNumber2String (pNUMBERSTRUCT pOptions, WCHAR *pchString)
{
UINT16 iTemp=0;
WCHAR *pchTemp=NULL;
pchTemp=pchString;
while (pOptions!=NULL)
{
iTemp=pOptions->iIndex;
WML_SetOneNumber(iTemp,&pchTemp);
if (pOptions->pNext!=NULL)
{
/* Set ';' character */
*pchTemp=WC(';');
pchTemp++;
}
pOptions=pOptions->pNext;
}
/* Set termination character */
*pchTemp=0;
}
/* Help function for AssembleKeyString.
Calculates the length for the result string
(excluding the termination character). */
UINT32 WML_GetAssembleLength (pUA pUser, pELEMENTTYPE pElement, BOOL *fError)
{
UINT32 iLength=0;
UINT32 iThis=0;
pELEMENTTYPE pContent=NULL;
pOPTIONELEMENT pOption=NULL;
/* Step through all elements on this level */
while (pElement!=NULL)
{
/* Check OPTGROUP or OPTION */
if (pElement->iType==Type_OPTGROUP)
{
pContent=WML_GetContent(pElement);
iLength+=WML_GetAssembleLength(pUser, pContent, fError);
}
else if (pElement->iType==Type_OPTION)
{
pOption=(OPTIONELEMENT*)(pElement);
if (pOption->fSelected)
{
iThis=WML_GetStringLength(pUser,pOption->pValue);
/* Don't add empty strings */
if (iThis>0)
{
/* Add length for data and ';'-character,*/
iLength+=iThis+1;
}
}
}
else
{
/* Error! */
*fError=TRUE;
}
pElement=pElement->pNextElement;
}
return iLength;
}
/* Help function for AssembleKeyString */
void WML_AddSelectedOptions (pUA pUser, pELEMENTTYPE pElement, WCHAR **ppchResult)
{
WCHAR *pchTemp=NULL;
pELEMENTTYPE pContent=NULL;
pOPTIONELEMENT pOption=NULL;
/* Step through all elements on this level */
while (pElement!=NULL)
{
/* Check OPTGROUP or OPTION */
if (pElement->iType==Type_OPTGROUP)
{
pContent=WML_GetContent(pElement);
WML_AddSelectedOptions(pUser, pContent, ppchResult);
}
else if (pElement->iType==Type_OPTION)
{
pOption=(OPTIONELEMENT*)(pElement);
if (pOption->fSelected)
{
/* Add option VALUE */
pchTemp=WML_GetString(pUser,pOption->pValue);
/* Don't add empty values */
if (pchTemp!=NULL)
{
if (*pchTemp!=0)
{
/* Copy string */
COPYSTRING(*ppchResult,pchTemp);
/* Update ppchResult pointer */
*ppchResult+=STRINGLENGTH(pchTemp);
/* Add ';'-character */
*(*ppchResult)++=WC(';');
}
/* Deallocate temp pointer */
DEALLOC (&pchTemp);
}
}
}
pElement=pElement->pNextElement;
}
}
/* Assembles the values in the selected OPTION elements
(those with the fSelected flag set) and returns a';'-
separated string. (E.g. 1 3 4 -> "[Value of option 1];
[Value of option 3];[Value of option 4]".) */
WCHAR *WML_AssembleKeyString (pUA pUser, pELEMENTTYPE pElement)
{
UINT32 iLength=0;
BOOL fError=FALSE;
WCHAR *pchResult=NULL;
WCHAR *pchResultTemp=NULL;
if (pElement!=NULL)
{
if ((pElement->iType==Type_OPTGROUP)||(pElement->iType==Type_OPTION))
{
/* Get result length. The length includes one ';' more
than it should, but no termination character, which
makes the length accurate. */
iLength=WML_GetAssembleLength(pUser, pElement, &fError);
if ((iLength>0)&&(!fError))
{
pchResult=NEWARRAY(WCHAR,iLength);
if (pchResult!=NULL)
{
pchResultTemp=pchResult;
/* Add the selected options to pchResult. */
WML_AddSelectedOptions (pUser,pElement,&pchResultTemp);
/* Insert termination character instead of
last ';'-character. */
*--pchResultTemp=0;
}
}
}
}
return pchResult;
}
pELEMENTTYPE WML_GetFirstSelectedOption(pELEMENTTYPE pElement, BOOL *pfFound)
{
pELEMENTTYPE pContent=NULL;
pELEMENTTYPE pResult=NULL;
pOPTIONELEMENT pOption=NULL;
/* Step through all elements on this level */
while ((pElement!=NULL)&&(!*pfFound))
{
/* Check OPTGROUP or OPTION */
if (pElement->iType==Type_OPTGROUP)
{
pContent=WML_GetContent(pElement);
pResult=WML_GetFirstSelectedOption(pContent,pfFound);
}
else if (pElement->iType==Type_OPTION)
{
pOption=(OPTIONELEMENT*)(pElement);
if (pOption->fSelected)
{
*pfFound=TRUE;
return pElement;
}
}
pElement=pElement->pNextElement;
}
return pResult;
}
/* Sets the variables to the correct values according to
the pOptions-list. */
void WML_SetSelectVariables (pUA pUser, pELEMENTTYPE pSelect, pNUMBERSTRUCT pOptions)
{
pSELECTELEMENT pSelectElm=NULL;
pELEMENTTYPE pContent=NULL;
pELEMENTTYPE pOption=NULL;
pOPTIONELEMENT pOptionElm=NULL;
WCHAR *pchResult=NULL;
WCHAR *pchTemp=NULL;
UINT16 iLength=0;
BOOL fFound=FALSE;
if ((pSelect!=NULL)&&(pOptions!=NULL))
{
if (pSelect->iType==Type_SELECT)
{
pSelectElm=(SELECTELEMENT*)(pSelect);
/* Single choice NAME */
if ((pSelectElm->pchName!=NULL)&&(!pSelectElm->fMultiple))
{
/* Set one option */
pContent=WML_GetContent(pSelect);
/* Get first selected option. */
pOption=WML_GetFirstSelectedOption(pContent, &fFound);
if (pOption!=NULL)
{
/* Get the value. */
pOptionElm=(OPTIONELEMENT*)(pOption);
pchResult=WML_GetString(pUser,pOptionElm->pValue);
if (pchResult!=NULL)
{
/* Set the key variable to the value. */
WML_SetVariable(pUser,pSelectElm->pchName,pchResult,FALSE);
DEALLOC(&pchResult);
}
}
}
/* Multiple choice NAME */
else if ((pSelectElm->pchName!=NULL)&&(pSelectElm->fMultiple))
{
/* Add all options */
pContent=WML_GetContent(pSelect);
if (pContent!=NULL)
{
/* Get value */
pchResult=WML_AssembleKeyString (pUser,pContent);
if (pchResult!=NULL)
{
/* Set variable */
WML_SetVariable(pUser,pSelectElm->pchName,pchResult,FALSE);
DEALLOC(&pchResult);
}
}
}
/* Single choice INAME */
if ((pSelectElm->pchIName!=NULL)&&(!pSelectElm->fMultiple))
{
{
/* Pick first element in list */
iLength=WML_GetNumberLength(pOptions->iIndex);
pchResult=NEWARRAY(WCHAR,iLength+1);
if (pchResult!=NULL)
{
pchTemp=pchResult;
/* Set variable */
if (pOptions!=NULL)
{
WML_SetOneNumber(pOptions->iIndex,&pchTemp);
/* Set termination character */
*pchTemp=0;
}
WML_SetVariable(pUser,pSelectElm->pchIName,pchResult,FALSE);
DEALLOC(&pchResult);
}
}
}
/* Multiple choice INAME */
else if ((pSelectElm->pchIName!=NULL)&&(pSelectElm->fMultiple))
{
{
/* Pick ALL elements in list */
iLength=WML_CalculateResultLength (pOptions);
pchResult=NEWARRAY(WCHAR,iLength+1);
if (pchResult!=NULL)
{
/* Set variable */
WML_ConvertNumber2String(pOptions,pchResult);
WML_SetVariable(pUser,pSelectElm->pchIName,pchResult,FALSE);
DEALLOC(&pchResult);
}
}
}
}
}
else if (pSelect!=NULL)
{
/* pOptions NULL -> set name to empty string
and iname to 0 if the select element is
multiple select. */
if (pSelect->iType==Type_SELECT)
{
pSelectElm=(SELECTELEMENT*)(pSelect);
if (pSelectElm->fMultiple)
{
/* Set name to empty string (remove variable) */
WML_SetVariable(pUser,pSelectElm->pchName,NULL,FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -