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

📄 wml_uafn.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
Converts a content-type string to byte
-----------------------------------------------------------------------*/
int SDL_ContentTypeTextToInt(void* pbText)
{
    BYTE iValue;
    BYTE* pbContentType;
    pbContentType = (BYTE*)pbText;

    if (pbText)
    {
      if (WSP_ConvertContentStringByte(&iValue, & pbContentType))
          return iValue;
    }
    return 0;
}

int SDL_GetCacheControl(void* pInHeaderList)
{
   HEADERDEF *pHeaderList = NULL;
   HEADERELEMENT *pHeaderElement = NULL;
   BOOL fError=TRUE;
   UINT32 uiDummy=0;
   pHeaderList = (HEADERDEF*)pInHeaderList;
   if( pHeaderList != NULL )
   {
 	  if( pHeaderList->pHeadList != NULL )
	  {
		pHeaderElement = WSP_GetHeaderWK ( 1, Field_Cache_Control, pHeaderList->pHeadList );
		if( pHeaderElement != NULL )
		{
			return WSP_GetCacheControlByte( pHeaderElement, &uiDummy, &fError );
		}
	  }
   }
   return 0;
}

BOOL CompareContentType (BYTE* pbAccept, BYTE* pbReceived)
{
    BYTE* p = NULL;
    BYTE* pRec = NULL;
    int idx = 0;

    p = pbAccept;

	while (*p) {
	  while (wae_iswhitespace (*p))
		  p++;

	  idx = 0;
	  pRec = pbReceived;
      
	  while (*p && (*p == *pRec)) {		/*prefix match */
      p++;
      pRec++;
      idx++;	
    }

	  if (idx) {
		  if (*p == '*')
        return TRUE;		/* check wildcard */

      if (((*p == '\0') || (*p == ',') || wae_iswhitespace (*p)) &&
          (*pRec == '\0'))
        return TRUE;  /* check absolute match */
	  }
	  while (*p && (*p++ != ','))
      ;	    /* to next , */
	}
    
	return FALSE;	
}

/*--------------------------------------------------------------------
Check if the contentype corresponds to the acceptcontenttype, 1 (TRUE) if OK
-----------------------------------------------------------------------*/
int SDL_CheckResponseContentType(const void* pResponseInfo, const void* pCompareContentType)
{
    BYTE    *pbRecievedContentType=NULL;
    BYTE    *pbAcceptContentType=NULL;
    BOOL    iRetVal=FALSE;
    BYTE    *pContentTypeText=NULL;

    if (pResponseInfo==NULL)
	  return FALSE;
    
	pContentTypeText = ((const CONTENTINFOSTRUCT*)pResponseInfo)->pContentTypeAsText;

    if (pContentTypeText==NULL || pCompareContentType==NULL)
      return FALSE;

    if (strstr( pCompareContentType, "*/*" )) /*gbu 000204*/
      return TRUE;

    /* make downcase work copies */
    pbRecievedContentType = NEWARRAY(BYTE,B_STRINGLENGTH((const char *)pContentTypeText)+1);
    if (pbRecievedContentType)
        DowncaseString (pbRecievedContentType, (BYTE*)pContentTypeText);

    pbAcceptContentType = NEWARRAY(BYTE,B_STRINGLENGTH(pCompareContentType)+1);
    if (pbAcceptContentType)
        DowncaseString (pbAcceptContentType, (BYTE*)pCompareContentType);

    iRetVal =  CompareContentType(pbAcceptContentType, pbRecievedContentType);

    DEALLOC(&pbAcceptContentType);
    DEALLOC(&pbRecievedContentType);

    return iRetVal;
}


#ifdef USE_KSC5601

WCHAR* STRCHR(WCHAR* str, WCHAR c)
{
	WCHAR	*p = str;

	for ( ; *p ; p++ )
		{
		if ( *p == c )
			return p;
		}
	return NULL;
}

#define wae_KCSKoreanFix(c)    (_wae_ctype[(c)] & (_C | _SP | _ARES | _UW | _DL))

BYTE*
b_EscapeStringSpecial (const BYTE* pbString)
{
  const BYTE *p;
  BYTE       *q, *s;
  UINT16     l = 0;
  UINT16     r = 0;

  if (pbString == NULL)
    return NULL;

  for (p = pbString; *p; p++) {
    if ( ((wae_KCSKoreanFix (*p)) && !((*p == 0x25)) ) || (*p > 0x7f))

      r++;
    else
      l++;
  }

  if ((s = NEWARRAY (BYTE, l + 3 * r + 1)) == NULL)
    return NULL;

  for (p = pbString, q = s; *p; p++) {
    if ( ((wae_KCSKoreanFix (*p)) && !((*p == 0x25)) ) || (*p > 0x7f)) {
/*    if ( *p > 0x7f ) {  modified by young 2000.6.16 */
      *q++ = '%';
      ByteToHex (*p, q);
      q += 2;
    }
    else
      *q++ = *p;
  }
  *q = '\0';

  return s;
}


BYTE* Unicode2byteSpecialKSCConvert(WCHAR* pURL)
{
	WCHAR* pURLString = pURL;
	WCHAR* pFragStart = NULL;
	WCHAR* pQueryStart = NULL;
	WCHAR* pQuerySubString = NULL;
	BYTE* pNewURL=NULL;
	BYTE* pByteQueryStart=NULL;
	BYTE* pURLStringAsByte=NULL;
	BYTE* pFragAsByte=NULL;
	UINT8 iFragLen=0;
	INT16 iQueryLen=0;
	INT16 iBaseLen = 0;
	INT16 iByteQueryLen=0;
	INT16 iTotalNewLength = 0;
	BOOL fDummy;
    INT16 iBuffLength;

    BYTE* pResultBuffer;

	if (!pURLString)
		return NULL;

	/* find start of query and fragment */
    pQueryStart = STRCHR(pURLString, (WCHAR)'?');
    pFragStart = STRCHR(pURLString, (WCHAR)'#');

	if (!pQueryStart)
	{
	   return wip_wchar2byte( pURLString, & fDummy );
	}
	pQueryStart++;
	if (pFragStart)	
	   iFragLen = (UINT8)STRINGLENGTH(pFragStart);

	iQueryLen = STRINGLENGTH(pQueryStart) - iFragLen;

	if (iQueryLen <=0)
	{
	   return wip_wchar2byte( pURLString, & fDummy );
	}

	/* copy query */
    
	pQuerySubString = NEWARRAY(WCHAR,iQueryLen+1);
    COPYSTRINGN( pQuerySubString, pQueryStart, iQueryLen);
	pQuerySubString[iQueryLen]=0;

	/* ... and transcode */

    iBuffLength = KSCStrLenOfUni((WCHAR*) pQuerySubString );
	if (iBuffLength)
	  pResultBuffer = NEWARRAY(BYTE,iBuffLength+1);

    iBuffLength = Uni2KSCString(pQuerySubString,pResultBuffer);
	DEALLOC(&pQuerySubString);

	/* escape result */
    pByteQueryStart = b_EscapeStringSpecial(pResultBuffer);
    
	DEALLOC(&pQuerySubString);
	if (pByteQueryStart)
		iByteQueryLen=B_STRINGLENGTH(pByteQueryStart);

	/* copy fragment */
	if (pFragStart)
	pFragAsByte = wip_wchar2byte( pFragStart, & fDummy );
	
	/* concatenate old url with new query and old fragment */
	iBaseLen = (pQueryStart-pURLString);
	iTotalNewLength = iBaseLen + iByteQueryLen + iFragLen;

	pNewURL = NEWARRAY(BYTE,iTotalNewLength+1);

	pURLStringAsByte = wip_wchar2byte( pURLString, & fDummy );

    B_COPYSTRINGN(pNewURL, pURLStringAsByte, iBaseLen);
	DEALLOC(&pURLStringAsByte);

	if (iByteQueryLen)
		B_COPYSTRINGN(& pNewURL[iBaseLen], pByteQueryStart, iByteQueryLen );
	if (iFragLen)
        B_COPYSTRING(& pNewURL[iBaseLen+iByteQueryLen], pFragAsByte);

    pNewURL[iTotalNewLength] = 0;

	DEALLOC(& pByteQueryStart );	
 	DEALLOC(& pResultBuffer );

	return pNewURL;
	
}

#endif


/*---------------------------- Functionality to handle new requests etc. ----------------------------------*/

/*-----------------------------------------------------------
Retrieves the URL to be used /and creates a history element if necessary) resolves it if necessary and
normalizes it. pURLElement can be different types of elements GoElement, ImageElement, or Text.
-------------------------------------------------------------*/
void SDL_GetElementURL( void* pUser, void* pURLElement, void** pURL, void** ppHistoryItem)
{
   WCHAR* pwchTemp=NULL;
   BYTE* pbResult=NULL;
/* gbu 000211   not used
   BYTE* pbQuery=NULL;
*/
   BYTE* pbTemp=NULL;
   ELEMENTTYPE* pElm;
   BOOL fDummy=FALSE;

   DEALLOC( pURL );

   if (pURLElement!=NULL)
   {
     pElm = ((ELEMENTTYPE*)pURLElement);
     switch (SDL_GetElementType(pURLElement))
	 {
		 case Type_IMG:
		   pwchTemp = SDL_GetText(pUser, ((IMGELEMENT*)(pElm))->pSrc );
		   pbTemp = wip_wchar2byte( pwchTemp, & fDummy );
		   break;
		 case Type_GO:
			 /* evalute the postfields etc. */
		   CreateNavigationData( (UA*)pUser, (GOELEMENT*)(pElm), (HISTORYITEM**)ppHistoryItem, & pbResult );
		   break;
		 case Type_A:
		   pwchTemp = SDL_GetText(pUser, ((AELEMENT*)(pElm))->pHref );
		   pbTemp = wip_wchar2byte( pwchTemp, & fDummy );
		   break;
		 case Type_GenericText:
		   pwchTemp = SDL_GetText(pUser, (ELEMENTTYPE*)pURLElement);  /*since this is a elementtype */
		   pbTemp = wip_wchar2byte( pwchTemp, & fDummy );
		   break;
     }
   }
   if (pwchTemp)
   {
     DEALLOC(&pwchTemp);
     /* resolve if necessary */
     b_Resolve (((UA*)pUser)->pbURLBase, pbTemp, & pbResult);
     DEALLOC(&pbTemp);
   }
   
   if (pbResult!=NULL)
   {
	 pbTemp = b_CompleteURLHeuristically(pbResult);  /* fix to append trailing slashes */
	 DEALLOC(&pbResult);
	 pbResult = pbTemp;
   }
   *pURL = pbResult;

   #ifdef WAE_DEBUG
     PrintChar("Get URL (from element)");
     PrintChar("Base:");
     PrintChar(((UA*)pUser)->pbURLBase);
     PrintChar("Go:");
     PrintChar(pbResult); 
   #endif
}

/*-----------------------------------------------------------------
-------------------------------------------------------------------*/
void CreateNavigationData( UA* pUserAgent, GOELEMENT* pGoElement, HISTORYITEM** ppHistoryItem, BYTE** ppTargetURL )
{
/* aspn 001101
    ELEMENTTYPE* pPostField = NULL;
*/
    BYTE* pbAccChar=NULL;
    INT16 iCharEnc=IANA_CHARSET_INVALID;
/* aspn 001101
    BOOL fContainsAcceptCharset=FALSE;
*/
    BOOL fDummy=FALSE;
    WCHAR* pwchTemp=NULL;
	BYTE* pbTemp=NULL;
	BYTE* pbTemp2=NULL;
	BYTE* pbSendData=NULL;
	UINT16 iSendDataLen=0;
	BOOL bIntraDeck = FALSE;
/* aspn 001101
    pPostField = SDL_GetElementContent( pGoElement);
*/
	SDL_GetElementContent( pGoElement);

	if (!pGoElement)
	{
	   *ppHistoryItem=NULL;
       *ppTargetURL=NULL;  
	   return;
	}
    
	/* head 010104, Not allowed to use this encodingtype with method get */
    if (pGoElement->iMethod==M_Get && pGoElement->iEnctype==GO_formdata)
	{
	   *ppHistoryItem=NULL;
       *ppTargetURL=NULL;  
	   return;
	}

	/* determine what char encoding to use */

    if ( pGoElement->pchAccChar )   /* if wml content contains ACCEPT-CHARSET */
	{
/* aspn 001101
	  fContainsAcceptCharset=TRUE;'
*/
      pbAccChar = NEWARRAY(BYTE, STRINGLENGTH( pGoElement->pchAccChar ) +1 );
	  if (pbAccChar)
	  {
         pbTemp = wip_wchar2byte( pGoElement->pchAccChar, & fDummy);
	 	 DowncaseString (pbAccChar, pbTemp);
		 DEALLOC(&pbTemp);
		 iCharEnc = IANA_CHARSET_LATIN1;

/* GBU 000204
         if (B_STRSTRING((CHAR*)pbAccChar, (CHAR*)"ucs-2"))
*/
         if (strstr((const char *)pbAccChar, "ucs-2"))
			iCharEnc= IANA_CHARSET_UCS2;

/* GBU 000204
		 if (B_STRSTRING((CHAR*)pbAccChar, (CHAR*)"us-ascii"))
*/
         if (strstr((const char *)pbAccChar, "us-ascii"))
			iCharEnc= IANA_CHARSET_USASCII;
        
/* GBU 000204
		 if (B_STRSTRING((CHAR*)pbAccChar, (CHAR*)"utf-8"))
*/
         if (strstr((const char *)pbAccChar, "utf-8"))
			iCharEnc= IANA_CHARSET_UTF8;
	    
	    DEALLOC(&pbAccChar);
	  }
    }
	/* else use document charset */
	else            
	  iCharEnc = pUserAgent->iTextEncodFormat;


	iSendDataLen = 0;
	/* create a target url  */
    pwchTemp = SDL_GetText(pUserAgent, pGoElement->pHref );

#ifdef USE_KSC5601
	pbTemp2 = Unicode2byteSpecialKSCConvert(pwchTemp);
#else
	pbTemp2 = wip_wchar2byte( pwchTemp, & fDummy );
#endif

    DEALLOC(&pwchTemp);

	pbTemp = b_EscapeBlanks( pbTemp2 );		/*  Maybe not nedded in KSC5601 mode */
	DEALLOC(&pbTemp2);
	pbTemp2 = pbTemp;
	if( pbTemp2[0] == '#' )
		bIntraDeck = TRUE;

	b_Resolve (pUserAgent->pbURLBase, pbTemp2, & pbTemp);
    DEALLOC(&pbTemp2);
	
	/* --- create post/query data, ignore postfields if it磗 the same deck  */
	if (  !bIntraDeck 
				|| !b_EqualURL ( ((UA*)pUserAgent)->pbURLBase, (BYTE*)pbTemp, ALL_COMP ^ FRAG_COMP)
				|| (pGoElement->iCacheControl == Cache_nocache) )  
	{
		if (pGoElement->iEnctype  == GO_urlencoded)
		{
		   CreatePostString( pUserAgent, pGoElement, iCharEnc, & pbSendData, & iSendDataLen);
		}
		else if (pGoElement->iEnctype  == GO_formdata)
		{
		   CreatePostBody( pUserAgent,  pGoElement, iCharEnc, & pbSendData, & iSendDataLen); 
		}
	}

	 *ppTargetURL = pbTemp;

    /* add any query data */

    if ( pGoElement->iMethod == M_Get && pGoElement->iEnctype == GO_urlencoded)
	{
      if (pbSendData)
	  {
	    *ppTargetURL = b_AppendToQuery (pbTemp, pbSendData);
	    DEALLOC(&pbTemp);
	  }
	  DEALLOC(&pbSendData);
	  iSendDataLen = 0;
	}

    /* to support stupid webservers with no ;charset implementation use cfg_wae_ua_methodPostCharsetOverride*/
    if ( cfg_wae_ua_methodPostCharsetOverride && !(pGoElement->pchAccChar) )
      iCharEnc=IANA_CHARSET_INVALID;

	/* create a history item from all data */
    if (ppHistoryItem) {
      Delete_HistoryItem ((void**)ppHistoryItem);
      *ppHistoryItem = CreateAndInitNewHistoryItem (NULL, NULL, pbSendData,

⌨️ 快捷键说明

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