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

📄 si_sq.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		{
			/* incorrect BP! The BPcallList must be emptied and ERR_WAE_WMLS_VERIFICATION returned */
			invokeEl->isDone = TRUE;
			invokeEl->errorCode = ERR_WAE_WMLS_VERIFICATION;
			SQ_ClearBPCallList( invokeEl );
			*pInvokeIDThatExecuted = invokeEl->invokeID;
			*pUApidInt = invokeEl->UApidAsInt;

			return eSs_error;
		}

		if (invokeEl->BPcallList->isInitialBPInvoked)
		{	/* first BP invoked */

			if ( invokeEl->theUAStruct->pbURLBase != NULL )
			{
				baseURLlen = B_STRINGLENGTH( invokeEl->theUAStruct->pbURLBase );

				baseURL = NEWARRAY( WCHAR, baseURLlen + 1 );
				baseURL[ baseURLlen ] = 0;
				for (i = 0; i < baseURLlen; i++)
				{
					baseURL[i] = (WCHAR)( invokeEl->theUAStruct->pbURLBase[i] );
				}

			}
			
			invokeEl->BPcallList->theSI = SI_NewWithArgString( invokeEl->invokeID, theBP, BPlen, IANAcharset, invokeEl->theUAStruct, invokeEl->BPcallList->callURL,
						baseURL, thisx->timeSlice, &siErrCode );

			DEALLOC( &baseURL );
		}
		else
		{	/* this BP called from another SI in the BPCallStack */
			/* then get funcName and args from the next BP in the BPCallList */
			/* check to see that these params exist */
			if ((invokeEl->BPcallList->next->theSI != NULL) &&
					SI_GetExtCalllParams_rest( invokeEl->BPcallList->next->theSI,
																			&funcName, &argOpS ) )
			{
				/* we have everything we need to build an SI */
				invokeEl->BPcallList->theSI = SI_NewWithArgOpS( invokeEl->invokeID, theBP, BPlen, IANAcharset,
        		invokeEl->theUAStruct, &funcName, &argOpS, invokeEl->BPcallList->callURL,
            invokeEl->BPcallList->next->theSI->baseURL,
						thisx->timeSlice, &siErrCode  );
			}
			/* ELSE the SI is still NULL and verification error occurs */
		}

		if (invokeEl->BPcallList->theSI == NULL)
		{
			/* BP incorrect (or the call function didn't exist/have the right number of args) */
			invokeEl->isDone = TRUE;
			invokeEl->errorCode = siErrCode;
			SQ_ClearBPCallList( invokeEl );
			*pInvokeIDThatExecuted = invokeEl->invokeID;
			*pUApidInt = invokeEl->UApidAsInt;

			return eSs_error;
		}
	}
	/* we now have an SI ready to run */

	siErrCode = SI_ExecBlock( invokeEl->BPcallList->theSI );


	/* if the error was is EXIT then it actually not really an error but it means that the
  execution should be aborted and a return value and control should be given back to the calling UA.
  Any Go or prev values should be correctly fetched. */
	if (siErrCode == ERR_WAE_WMLS_EXIT)
	{	/* if the WMLS lib func Lang.exit was called */
		pstructBPElement	pEl = NULL;
		pstructSI					lastSIWithBrowserAction = NULL;
    BOOL 							fDone;

		invokeEl->isDone = TRUE;
		siErrCode = ERR_WAE_WMLS_NONE;

		siResult = SI_GetReturnVal( invokeEl->BPcallList->theSI );

		invokeEl->isDone = TRUE;
		invokeEl->errorCode = siErrCode;
		invokeEl->theResult = siResult;
		siResult = NULL;
		invokeEl->browserGoUrl = NULL;
		invokeEl->browserPrev = FALSE;

    /* get the browser action invoked, if any */
    /* have to go through the BP list and get the last
       BP which invoked a browser action */
    /* since it is a stack then we only have to find the first one (i.e the latest) */
		fDone = FALSE;
    pEl = invokeEl->BPcallList;
    while (pEl != NULL && !fDone )
    {
    	if (pEl->theSI && pEl->theSI->WMLBrowserActionInvoked)
      {
      	lastSIWithBrowserAction = pEl->theSI;
        fDone = TRUE;
      }
			pEl = pEl->next;      
    }
    if (lastSIWithBrowserAction != NULL)
    {	/* there was a browser action invoked so get it */
			if (lastSIWithBrowserAction->WMLBrowser_goURL != NULL)
      {
      	invokeEl->browserGoUrl = lastSIWithBrowserAction->WMLBrowser_goURL;
				lastSIWithBrowserAction->WMLBrowser_goURL = NULL;
      }
      else
      {
      	invokeEl->browserPrev = lastSIWithBrowserAction->WMLBrowser_prev;
      }
    }

		SQ_ClearBPCallList( invokeEl );
		*pInvokeIDThatExecuted = invokeEl->invokeID;
		*pUApidInt = invokeEl->UApidAsInt;

		if (invokeEl->browserPrev)
		{
			return eSs_done_prev;
		}
		else if (invokeEl->browserGoUrl != NULL)
		{
			return eSS_done_go;
		}
		else
		{
			return eSs_done;
		}
	}

	if (siErrCode != ERR_WAE_WMLS_NONE)
	{	/* if an error has occured */
		invokeEl->isDone = TRUE;
		invokeEl->errorCode = siErrCode;
		SQ_ClearBPCallList( invokeEl );
		*pInvokeIDThatExecuted = invokeEl->invokeID;
		*pUApidInt = invokeEl->UApidAsInt;

		return eSs_error;
	}
	else
	{	/* no error */
		switch (invokeEl->BPcallList->theSI->returnInfo)
		{
			case SI_RETURN_DONE:
				if (invokeEl->BPcallList->theSI->WMLBrowserActionInvoked)
				{	/* get the go/prev parameters */
					goURL = invokeEl->BPcallList->theSI->WMLBrowser_goURL;
					invokeEl->BPcallList->theSI->WMLBrowser_goURL = NULL;		/* this has been taken over */
					goPrev = invokeEl->BPcallList->theSI->WMLBrowser_prev;
				}
				else
				{	/* no get/prev parameters */
					goURL = NULL;
					goPrev = FALSE;
				}
				siResult = SI_GetReturnVal( invokeEl->BPcallList->theSI );
				if (siResult == NULL)
				{	/* ERROR: stack underflow! */
					DEALLOC( &goURL );
					invokeEl->isDone = TRUE;
					invokeEl->errorCode = ERR_WAE_WMLS_STACK_UNDERFLOW;
					SQ_ClearBPCallList( invokeEl );
					*pInvokeIDThatExecuted = invokeEl->invokeID;
					*pUApidInt = invokeEl->UApidAsInt;

					return eSs_error;
				}

				/* ELSE: OK. We have now extracted results from the SI  */
				/* now we must put the result to the caller (another si or else the invoke is done) */

				if (invokeEl->BPcallList->next != NULL)
				{	/* another si must be given the results and the old si must be removed */
					/* ASSERT( invokeEl->BPcallList->next->theSI != NULL ) */
					SI_ReceiveCalledSIReturnVal( invokeEl->BPcallList->next->theSI, &siResult,
																				invokeEl->BPcallList->theSI->WMLBrowserActionInvoked,
																				goPrev, &goURL );
					/* now remove the old BPelement with the finished SI */
					BPel = invokeEl->BPcallList;
					invokeEl->BPcallList = invokeEl->BPcallList->next;
					SQ_DeleteBPElement( &BPel );

					*pInvokeIDThatExecuted = invokeEl->invokeID;
					*pUApidInt = invokeEl->UApidAsInt;
					return eSs_more;
				}
				else
				{	/* the invoke is done and the results must be stored in the invokeHead */
					invokeEl->isDone = TRUE;
					invokeEl->errorCode = ERR_WAE_WMLS_NONE;
					invokeEl->theResult = siResult;
					siResult = NULL;
					invokeEl->browserGoUrl = goURL;
					goURL = NULL;
					invokeEl->browserPrev = goPrev;

					SQ_ClearBPCallList( invokeEl );
					*pInvokeIDThatExecuted = invokeEl->invokeID;
					*pUApidInt = invokeEl->UApidAsInt;

					if (invokeEl->browserPrev)
					{
						return eSs_done_prev;
					}
					else if (invokeEl->browserGoUrl != NULL)
					{
						return eSS_done_go;
					}
					else
					{
						return eSs_done;
					}
				}

			case SI_RETURN_MORE:
				/* just return control */
				*pInvokeIDThatExecuted = invokeEl->invokeID;
				*pUApidInt = invokeEl->UApidAsInt;
				return eSs_more;

			case SI_RETURN_EXTERNAL:
				invokeEl->isInWaitState = TRUE;
				*pInvokeIDThatExecuted = invokeEl->invokeID;
				*pUApidInt = invokeEl->UApidAsInt;
				/* ASSERT( invokeEl->BPcallList->theSI->returnParams != NULL ) */
				if (invokeEl->BPcallList->theSI->returnParams->islibCall)
				{
					return eSs_lib;
				}
				else
				{
					/* a call to a new BP has been made thus a new BPelement must be created to hold
						the callUrl and to later be filled with BP and its SI */
					if (SI_GetExtCalllParams_URL( invokeEl->BPcallList->theSI, &callURL ))
					{
						SQ_CreateAndAddBPElement( invokeEl, NULL, 0, IANA_CHARSET_INVALID,
		            &callURL, FALSE );
						return eSs_extFunc;
					}
					else
					{	/* ERROR: no call url for the external call */
						invokeEl->isDone = TRUE;
						invokeEl->errorCode = ERR_WAE_WMLS_LOAD;
						SQ_ClearBPCallList( invokeEl );
						*pInvokeIDThatExecuted = invokeEl->invokeID;
						*pUApidInt = invokeEl->UApidAsInt;
											
						return eSs_error;
					}
				}

			case SI_RETURN_EXTERNAL_NO_PARAMS:
				/* signal that there is nothing to proccess for now, not until there is an external response (e.g. through an adaptor call) */
				invokeEl->isInWaitState = TRUE;
				*pInvokeIDThatExecuted = 0;
				return eSs_more;

			default:
				/* an error has occured since the returnInfo value was incorrect */
				invokeEl->isDone = TRUE;
				invokeEl->errorCode = siErrCode;
				SQ_ClearBPCallList( invokeEl );
				*pInvokeIDThatExecuted = invokeEl->invokeID;
				*pUApidInt = invokeEl->UApidAsInt;

				return eSs_error;

		}
	}
}



BOOL SQ_GetResult( pstructSQ thisx, UINT8 invokeID, WCHAR **pResultStr )
/* the pResultStr must be NULL!!! */
{
	pstructVar						theResultVar = NULL;
	pstructInvokeHead			invokeEl = NULL;

	
	if ((thisx == NULL) || (*pResultStr != NULL))
	{	/* error! */
		return FALSE;
	}

	invokeEl = SQ_FindInvokeHead( thisx, invokeID );
	if (invokeEl == NULL)
	{	/* no invoke that matched the invoke ID */
		return FALSE;
	}

	if (( ! invokeEl->isDone) || (invokeEl->theResult == NULL))
	{	/* no return value to collect */
		return FALSE;
	}

	theResultVar = invokeEl->theResult;
	invokeEl->theResult = NULL;	/* we are now the owner of the var  */

	if ((invokeEl->browserGoUrl == NULL) && ( ! invokeEl->browserPrev))
	{	/* no more results to retrieve and the invoke is removed */
		SQ_RemoveAndDeleteInvokeHeadFromQ( thisx, &invokeEl );
	}

	/* now convert the var to a string */
	if (theResultVar->type == typeInvalid) {
		Var_NewString( theResultVar, 7 );
		theResultVar->val.theString[0] = WC('i');
		theResultVar->val.theString[1] = WC('n');
		theResultVar->val.theString[2] = WC('v');
		theResultVar->val.theString[3] = WC('a');
		theResultVar->val.theString[4] = WC('l');
		theResultVar->val.theString[5] = WC('i');
		theResultVar->val.theString[6] = WC('d');
	}
	else {
		if ( ! (VCR_OK == Var_Convert( theResultVar, typeString ))) {
			/* could not convert */
			Var_Delete( &theResultVar );
			return FALSE;
		}
	}

	/* now snatch the string... */ 
	*pResultStr = theResultVar->val.theString;

	/* ...and dealloc the variable */
	theResultVar->val.theString = NULL;
	theResultVar->theStringLen = 0;
	Var_Delete( &theResultVar );

	/* done! */
	return TRUE;
}


BOOL SQ_GetPrevParams( pstructSQ thisx, UINT8 invokeID )
{
	pstructInvokeHead			invokeEl = NULL;


	if (thisx == NULL)
	{	/* error! */
		return FALSE;
	}

	invokeEl = SQ_FindInvokeHead( thisx, invokeID );
	if (invokeEl == NULL)
	{	/* no invoke that matched the invoke ID */
		return FALSE;
	}

	if (( ! invokeEl->isDone) || ( ! invokeEl->browserPrev))
	{	/* no value to collect */
		return FALSE;
	}

	/* the one getting the params are now the owner of the strings  */

	if (invokeEl->theResult == NULL)
	{	/* no more results to retrieve and the invoke is removed */
		SQ_RemoveAndDeleteInvokeHeadFromQ( thisx, &invokeEl );
	}

	/* done! */
	return TRUE;
}


BOOL SQ_GetGoParams( pstructSQ thisx, UINT8 invokeID, BYTE **pGoUrl )
{
	pstructInvokeHead			invokeEl = NULL;
  BOOL									fDummy;


	if ((thisx == NULL) || (*pGoUrl != NULL))
	{	/* error! */
		return FALSE;
	}

	invokeEl = SQ_FindInvokeHead( thisx, invokeID );
	if (invokeEl == NULL)
	{	/* no invoke that matched the invoke ID */
		return FALSE;
	}

	if (( ! invokeEl->isDone) || (invokeEl->browserPrev))
	{	/* no value to collect */
		return FALSE;
	}

	/* make a BYTE* copy that the receiver is responsible for destroying */
	*pGoUrl = wip_wchar2byte( invokeEl->browserGoUrl, &fDummy );	/* the fDummy is used beacuse we don't care about overflow */
	DEALLOC( &invokeEl->browserGoUrl ); /* original not needed any more */

	if (invokeEl->theResult == NULL)
	{	/* no more results to retrieve and the invoke is removed */
		SQ_RemoveAndDeleteInvokeHeadFromQ( thisx, &invokeEl );
	}

	/* done! */
	return TRUE;
}



BOOL SQ_GetError( pstructSQ thisx, UINT8 invokeID, enumErrorCode *errCode )
{
	pstructInvokeHead			invokeEl = NULL;


	if (thisx == NULL)
	{	/* error! */
		return FALSE;
	}

	invokeEl = SQ_FindInvokeHead( thisx, invokeID );
	if (invokeEl == NULL)
	{	/* no invoke that matched the invoke ID */
		return FALSE;
	}

	if (( ! invokeEl->isDone) || (invokeEl->errorCode == ERR_WAE_WMLS_NONE))
	{	/* no value to collect */
		return FALSE;
	}

	*errCode = invokeEl->errorCode;

	SQ_RemoveAndDeleteInvokeHeadFromQ( thisx, &invokeEl );

	/* done! */
	return TRUE;
}



BOOL SQ_GetExternalCallParams( pstructSQ thisx, UINT8 invokeID, BYTE **pTheURL )
{
	pstructInvokeHead			invokeEl = NULL;
	BOOL									fDummy;
	
	if ((thisx == NULL) || (*pTheURL != NULL))
	{	/* ERROR: not all parameters are correct! */
		return FALSE;
	}

	/* find the invoke which has the supplied invoke ID */
	invokeEl = SQ_FindInvokeHead( thisx, invokeID );
	if (invokeEl == NULL)
	{	/* no invoke that matched the invoke ID */
		return FALSE;
	}

	/* now see if there is an SI with external params */
	
	if ( (invokeEl->BPcallList != NULL) && 
			(invokeEl->BPcallList->theSI == NULL) &&
			( ! invokeEl->BPcallList->isInitialBPInvoked) &&
			(invokeEl->BPcallList->callURL != NULL))
	{
		/* everything went fine */
		/* make a BYTE* copy of the URL. (The original is still needed) */
		*pTheURL = wip_wchar2byte( invokeEl->BPcallList->callURL , &fDummy); /* we dont' care about overflow, that's why we use fDummy */
		return TRUE;
	}
	else
	{	/* something went wrong */
		return FALSE;
	}
}



BOOL SQ_GetLibCallParams( pstructSQ thisx, UINT8 invokeID, UINT16 *pLibIndex, UINT8 *pFuncIndex, 
															pstructOpS *pArgOpS )
{
	pstructInvokeHead			invokeEl = NULL;

	
	if ((thisx == NULL) || (*pArgOpS != NULL))
	{	/* ERROR: not all parameters are correct! */

⌨️ 快捷键说明

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