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

📄 myiweb.c

📁 BREW程序:BREW手机上的Web访问程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	// for wont of memory
	pwri = IWEBRESP_GetInfo(pwa->piWResp);
	
	//   ND_Print(pMe, "** got response...\n** info code: %d\n", pwri->nCode);
	
	// body may be NULL
	if ((ISource *)0 != pwri->pisMessage) 
	{
		IHTMLVIEWER_LoadSource(pwa->m_pHTMLViewer, pwri->pisMessage);
	}
	
}

/*===========================================================================

FUNCTION: myiweb_Header

DESCRIPTION:
   Received header callback for a web transaction. cpszName is NULL in the case 
   of continuation header line parts.

PARAMETERS:
   p: a myiweb (the subscriber)
   cpszName: the name of the web header (like "Content-Type")
   pglVal: the value of the header, like "text/html"

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void myiweb_Header(void *p, const char *cpszName, GetLine *pglVal)
{
   myiweb *pwa = (myiweb *)p;
  
  
 //  if (pMe->m_bRS) { // If response is to be displayed
      if ((char *)0 != cpszName) {
        // ND_Print(pMe, "%s:", cpszName);
      }
      //ND_Print(pMe, "%s\n", pglVal->psz);
  // }
}

/*===========================================================================

FUNCTION: myiweb_Status

DESCRIPTION:
   Web status callback for a Web transaction 

PARAMETERS:
   p: a myiweb (the subscriber)
   ws: type of status
   pVal: unused as of yet

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void myiweb_Status(void *p, WebStatus ws, void *pVal)
{
   AECHAR     szText[32];
   myiweb * pMe = (myiweb *)p;
   
   (void)pVal;

   switch (ws) {
   case WEBS_CANCELLED:
	  ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_CANCELLED, szText, sizeof(szText));
      break;
   case WEBS_GETHOSTBYNAME:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_GETHOSTBYNAME,szText, sizeof(szText));
      break;          
   case WEBS_CONNECT:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_CONNECT, szText, sizeof(szText));
      break;
   case WEBS_SENDREQUEST:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_SENDREQUEST, szText, sizeof(szText));
      break;
   case WEBS_READRESPONSE:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_READRESPONSE, szText, sizeof(szText));
      break;
   case WEBS_GOTREDIRECT:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_GOTREDIRECT, szText, sizeof(szText));
      break;
   case WEBS_CACHEHIT:
      ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_WEBS_CACHEHIT, szText, sizeof(szText));
      break;
   }

   // show that status!
   if ((AECHAR *)0 != szText) 
   {
      myiweb_DisplayInfo(pMe,szText);
   }
}

/*===========================================================================

FUNCTION: myiweb_Stop

DESCRIPTION:
   Halts a web transaction, wrapped/represented by a myiweb

PARAMETERS:
   pwa: the myiweb

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void myiweb_Stop(myiweb *pwa)
{
   // this cancels any pending web transaction, or readable on the 
   // response body.  if nothing is pending, this has no effect
   CALLBACK_Cancel(&pwa->cb);
   
   // then clean up, if necessary
   if ((char *)0 != pwa->pszPostData) {
      *pwa->pszPostData = 1; // write delimiter back in, if any
      pwa->pszPostData = 0;
   }
	if (pwa->piWResp)
	{
		IWEBRESP_Release(pwa->piWResp);
		pwa->piWResp= NULL;
	}

	if (pwa->m_pIWeb) 
	{
		IWEB_Release(pwa->m_pIWeb);
		pwa->m_pIWeb = NULL;
	}

	if (pwa->m_BodyBuffer)
	{
		FREE(pwa->m_BodyBuffer);
		pwa->m_BodyBuffer = NULL;
	}
	pwa->m_BodySize = 0;
	pwa->m_BodyAllocSize = 0;

}
static void myiweb_DownloadFile(void * p)
{
	myiweb *pMe = (myiweb *)p;
	
	WebRespInfo *pwri;
	char targetFile[24];
	byte buf[1024];
	int ByteCount;
	IFile * pFile;
	   
	   // get information about how the web transaction went
	   // pwa->piWResp is ***NEVER NULL***, even though the transaction may fail
	   // for wont of memory

	   pwri = IWEBRESP_GetInfo(pMe->piWResp);
	   
	   //   ND_Print(pMe, "** got response...\n** info code: %d\n", pwri->nCode);
	   if(WEB_ERROR_SUCCEEDED(pwri->nCode))
		   DBGPRINTF("request successful!");
	   else{
		   WEB_ERROR_MAP(pwri->nCode);
		   DBGPRINTF("request successful %i",pwri->nCode);
	   }
	   // body may be NULL
	   if ((ISource *)0 != pwri->pisMessage) 
	   {
		   ISource * pISource = pwri->pisMessage;
		   ByteCount =	ISOURCE_Read(pISource, (byte*)buf, sizeof(buf));

		   switch(ByteCount)
		   {
		   case ISOURCE_END:
			   if (pMe->m_BodySize < pMe->m_BodyAllocSize)
				   pMe->m_BodyBuffer[pMe->m_BodySize] = 0;
			   else
				   pMe->m_BodyBuffer[pMe->m_BodyAllocSize - 1] = 0;
			   
			   if(!pMe->m_pIFileMgr)
				   ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_FILEMGR, (void **)&pMe->m_pIFileMgr);
			   if(pMe->m_iMediaType == 1)
			   {
				   if (IFILEMGR_MkDir(pMe->m_pIFileMgr, "pic") != SUCCESS)
				   {	
					   IFILEMGR_Release(pMe->m_pIFileMgr);
					   pMe->m_pIFileMgr = NULL;
					   return;
				   }
				   STRCPY(targetFile,"pic\\");
			   }else if(pMe->m_iMediaType == 2)
			   {
				   if (IFILEMGR_MkDir(pMe->m_pIFileMgr, "music") != SUCCESS)
				   {	
					   IFILEMGR_Release(pMe->m_pIFileMgr);
					   pMe->m_pIFileMgr = NULL;
					   return;
				   }
				   STRCPY(targetFile,"music\\");
			   }
			   STRCAT(targetFile,pMe->m_pszFileName);
			   if(IFILEMGR_Test(pMe->m_pIFileMgr,targetFile)==SUCCESS)
				   IFILEMGR_Remove(pMe->m_pIFileMgr,targetFile);
			   pFile= IFILEMGR_OpenFile(pMe->m_pIFileMgr,targetFile,_OFM_CREATE);
			   IFILE_Write(pFile,(void*)pMe->m_BodyBuffer,pMe->m_BodyAllocSize);
			   IFILE_Release(pFile);
			   IFILEMGR_Release(pMe->m_pIFileMgr);
			   pMe->m_pIFileMgr = NULL;
			   
			   {
				   AECHAR szFile[64];
				   AECHAR szText[64];
				   STRTOWSTR(pMe->m_pszFileName,szFile,64);
				   ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_DOWNLOAD_OK, szText, sizeof(szText));
				   WSTRCAT(szFile,szText);
				   myiweb_DisplayInfo(pMe,szFile);
			   }
			   FREEIF(pMe->m_pszFileName);
			   break;
		   case ISOURCE_ERROR:
			   break;
		   case ISOURCE_WAIT:
			   ISOURCE_Readable(pISource, &pMe->cb);
			   break;
		   default:
			   
			   if (ByteCount)
			   {
				   if (pMe->m_BodySize + ByteCount > pMe->m_BodyAllocSize)
				   {
					   const int NewSize = pMe->m_BodyAllocSize + 1024;
					   byte* NewBuf = (byte*)REALLOC(pMe->m_BodyBuffer, NewSize);
					   
					   if (NewBuf)
					   {
						   pMe->m_BodyBuffer = NewBuf;
						   pMe->m_BodyAllocSize = NewSize;
					   }
				   }
				   if(pMe->m_BodySize + ByteCount <= pMe->m_BodyAllocSize)
				   {
					   MEMCPY(pMe->m_BodyBuffer + pMe->m_BodySize, buf, ByteCount);
					   pMe->m_BodySize += ByteCount;
				   }
			   }
			   
			   ISOURCE_Readable(pISource, &pMe->cb);
			   break;
		   } 
	   }	   
   
}
static void  myiweb_ShowFileMenu(myiweb* pMe)
{
	CtlAddItem  ai;
	if (! pMe->m_pIFileMenu)
		ISHELL_CreateInstance(pMe->pIShell, AEECLSID_MENUCTL, (void **)&pMe->m_pIFileMenu) ;
	
	IMENUCTL_SetTitle(pMe->m_pIFileMenu,MYIWEB_RES_FILE,IDS_TITLE,NULL);

	ai.pText = NULL;
	ai.pImage = NULL;
	ai.pszResImage = MYIWEB_RES_FILE;
	ai.pszResText = MYIWEB_RES_FILE;
	ai.wFont = AEE_FONT_NORMAL;
	ai.dwData = NULL;
	
	ai.wText = IDS_MEDIA_PIC;   
	ai.wImage = IDB_MENU;
	ai.wItemID = IDS_MEDIA_PIC;
	
	
	// Add the item to the menu control
	if(IMENUCTL_AddItemEx(pMe->m_pIFileMenu, &ai )==FALSE)
	{
		IMENUCTL_Release(pMe->m_pIFileMenu);
		pMe->m_pIFileMenu = NULL;
		return;
	}
	
	ai.wText = IDS_MEDIA_MUSIC;
	ai.wItemID = IDS_MEDIA_MUSIC;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIFileMenu, &ai );

	IMENUCTL_SetActive(pMe->m_pIFileMenu,TRUE);
	pMe->m_iAppStatus = 10;
}
static char * myiweb_GetFileName(const char * psz)
{
   char *   pszName = STRRCHR(psz, (int)DIRECTORY_CHAR);

   if (pszName)
      pszName++;
   else
      pszName = (char *)psz;

   return pszName;
}

static boolean myiweb_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID, AECHAR * pText, uint16 wImageID, uint16 wItemID, uint32 dwData)
{
   CtlAddItem  ai;

   // Fill in the CtlAddItem structure values
   ai.pText = pText;
   ai.pImage = NULL;
   ai.pszResImage = MYIWEB_RES_FILE;
   ai.pszResText = MYIWEB_RES_FILE;
   ai.wText = wTextID;
   ai.wFont = AEE_FONT_NORMAL;
   ai.wImage = wImageID;
   ai.wItemID = wItemID;
   ai.dwData = dwData;

   // Add the item to the menu control
   return IMENUCTL_AddItemEx( pMenu, &ai );
}

⌨️ 快捷键说明

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