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

📄 myiweb.step1

📁 BREW程序:BREW手机上的Web访问程序
💻 STEP1
📖 第 1 页 / 共 2 页
字号:
        (ISHELL_CreateInstance(pMe->pIShell, AEECLSID_WEB, (void **)(&pMe->m_pIWeb)) != SUCCESS))
   {
      IAPPLET_Release((IApplet*)pMe);
      return FALSE;
   }
   IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, (PFNHVIEWNOTIFY)myiwebhtml_NotifyCB, pMe);
   IHTMLVIEWER_SetProperties(pMe->m_pHTMLViewer, HVP_SCROLLBAR);

   // Get device screen rect
   SETAEERECT(&pMe->m_rc, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen);

    // Initialize the IWeb with a few options
   {
      int    i = 0;
      WebOpt awo[10]; 

      // set the IWeb connect timeout to 10 seconds.  this also sets the 
      // failover timeout, if unset, or set to 0, IWeb uses the system 
      // default (30 seconds unless an OEM changes it)
      awo[i].nId  = WEBOPT_CONNECTTIMEOUT;
      awo[i].pVal = (void *)10000;
      i++;

      // test user-agent, uncomment this section to ship your own user-agent 
      // string. if unset, IWeb will send a default.  If set to NULL, no 
      // user agent header will be sent */

      // Set TEST_USER_AGENT in the NetDiagnostics project settings to all
      // shipping of your own user agent.

#ifdef TEST_USER_AGENT
      awo[i].nId  = WEBOPT_USERAGENT;
      awo[i].pVal = (void *)WEBBER_USERAGENT;
      i++;
#endif 

      // test nowaitconn, this only comes into effect if you build webber 
      // with multiple myiwebs (see the definition of struct Webber)
      awo[i].nId  = WEBOPT_FLAGS;
      awo[i].pVal = (void *)WEBREQUEST_NOWAITCONN;
      i++;
      

      // test forcenew, uncomment this section to try multiple simultaneous
      // "forced" new connections. Forced new connections are not kept alive
      // unless they are the first forced new connection to a host
#ifdef TEST_FORCENEWCONN
      awo[i].nId  = WEBOPT_FLAGS;
      awo[i].pVal = (void *)WEBREQUEST_FORCENEWCONN;
      i++;
#endif 

#ifdef TEST_USER_AGENT
      // turn off HTTP over HTTP proxying
      awo[i].nId  = WEBOPT_PROXYSPEC;
      awo[i].pVal = (void *)"http:///";
      i++;

      // turn on ALL proxying.  Proxyspecs are examined in WebOpt
      // order, so in this list, with the above and below PROXYSPECs,
      // everything except HTTP will be proxied through
      // http://webproxy.yourdomain.com:8080, (which you'll have to
      // set up to test, sorry
      awo[i].nId  = WEBOPT_PROXYSPEC;
      awo[i].pVal = (void *)"*:///http://webproxy.yourdomain.com:8080";
      i++;
#endif

      // Marks the end of the array of WebOpts
      awo[i].nId  = WEBOPT_END;
      
      // Add Options
      IWEB_AddOpt(pMe->m_pIWeb,awo);
   }

   	pMe->m_BodyBuffer = NULL;
	pMe->m_BodySize = 0;
	pMe->m_BodyAllocSize = 0;
    // if there have been no failures up to this point then return success
    // end of lab 1
    return TRUE;
}

// this function is called when your application is exiting
void myiweb_FreeAppData(myiweb* pMe)
{
    // insert your code here for freeing any resources you have allocated...
	
	if( pMe->m_pIMenu )
	{
		IMENUCTL_Release(pMe->m_pIMenu);
		pMe->m_pIMenu = NULL;
	}
	// lab 2

	// end of lab 2
//lab 1
	if(pMe->m_pHTMLViewer)
	{
		IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, NULL, pMe);
		IHTMLVIEWER_Release(pMe->m_pHTMLViewer);
		pMe->m_pHTMLViewer = NULL;
	}
	if(pMe->m_pIWeb)
	{
		IWEB_Release(pMe->m_pIWeb);
		pMe->m_pIWeb = NULL;
	}
	// end of lab 1
}
static void  myiweb_ShowMenu(myiweb* pMe)
{	
	CtlAddItem  ai;
	if (! pMe->m_pIMenu)
		ISHELL_CreateInstance(pMe->pIShell, AEECLSID_MENUCTL, (void **)&pMe->m_pIMenu) ;
	
	IMENUCTL_SetTitle(pMe->m_pIMenu,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_WCONNECT;   
	ai.wImage = IDB_MENU;
	ai.wItemID = IDS_WCONNECT;
	
	
	// Add the item to the menu control
	if(IMENUCTL_AddItemEx(pMe->m_pIMenu, &ai )==FALSE)
	{
		IMENUCTL_Release(pMe->m_pIMenu);
		return;
	}
	
	ai.wText = IDS_FILE_MGR;
	ai.wItemID = IDS_FILE_MGR;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );

	ai.wText = IDS_FAVOURITE;
	ai.wItemID = IDS_FAVOURITE;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );

	ai.wText = IDS_ABOUT;
	ai.wItemID = IDS_ABOUT;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );
	
	IMENUCTL_SetActive(pMe->m_pIMenu,TRUE);
	pMe->m_iAppStatus = 0;
}
// lab 2

// end of lab 2
//lab 1
static void myiwebhtml_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
   myiweb* pMe = (myiweb*) pvUser;   

   switch( pNotify->code )
   {

   case HVN_REDRAW_SCREEN:
      IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
      IHTMLVIEWER_Redraw(pMe->m_pHTMLViewer);
      break;

   case HVN_JUMP:
   case HVN_SUBMIT:
   // lab 4

	   // end of lab 4
	 //  IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, NULL, pMe);
	 // lab 3

	   // end of lab 3
	   // lab 4

		// lab 4
      break;

   case HVN_DONE:
      IHTMLVIEWER_SetRect(pMe->m_pHTMLViewer, &pMe->m_rc);
      IHTMLVIEWER_Redraw( pMe->m_pHTMLViewer );
      break;

   }
}
// end of lab 1
//lab 1
static void myiweb_Start(myiweb *pMe, char *pszUrl,int iPage)
{
   ISourceUtil *pisu;
	pMe->m_iAppStatus = 1;
   // look to see if there's POST data, this is totally non-standard, but 
   // easy to put into tests
   pMe->pszPostData = STRCHR(pszUrl, 1);
   
   // if there's post data, construct a stream for IWeb to consume
   if ((char *)0 != pMe->pszPostData) 
   {
      *pMe->pszPostData = 0;
      if (SUCCESS == ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL, (void **)&pisu)) 
	  {
         
         ISOURCEUTIL_PeekFromMemory(pisu, pMe->pszPostData + 1, 
                                    STRLEN(pMe->pszPostData + 1), 0, 0,
                                    &pMe->pipPostData);
         ISOURCEUTIL_Release(pisu);
      }
   }

   // initialize the callback, where I'll be called when the request
   // completes
   if(iPage == 0)
   {
	   CALLBACK_Cancel(&pMe->cb);
	   CALLBACK_Init(&pMe->cb, myiweb_GotResp, pMe);
   }// lab 4
  
   // end of lab 4

   // start transaction, pass callbacks for web status, web headers
   // the extra WEBOPT_HEADER is used to help test what's sent 
   // (snoop.sh above shows all the headers)
   if(!pMe->m_pIWeb)
	   ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEB, (void**)(&pMe->m_pIWeb));
   if ((IPeek *)0 != pMe->pipPostData) {
      IWEB_GetResponse(pMe->m_pIWeb,
                       (pMe->m_pIWeb, &pMe->piWResp, &pMe->cb, pszUrl, 
                        WEBOPT_HANDLERDATA, pMe,
                        WEBOPT_HEADER, "X-Method: POST\r\n", /* for kicks */
                        //lab 2

                        // end lab 2
                        WEBOPT_METHOD, "POST",
                        WEBOPT_BODY, pMe->pipPostData,
                        WEBOPT_CONTENTLENGTH, STRLEN(pMe->pszPostData + 1),
                        WEBOPT_END));
   } else {
      IWEB_GetResponse(pMe->m_pIWeb,
                       (pMe->m_pIWeb, &pMe->piWResp, &pMe->cb, pszUrl, 
                        WEBOPT_HANDLERDATA, pMe, 
                        WEBOPT_HEADER, "X-Method: GET \r\n",
                        //lab 2

                        //end of lab 2
                        WEBOPT_END));
   }
}
//end of lab 1
// lab 1
static void myiweb_GotResp(void *p)
{
	myiweb *pwa = (myiweb *)p;
	
	WebRespInfo *pwri;
	
	// 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(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);
	}
	
}
// end of lab 1
/*===========================================================================

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
===========================================================================*/
// lab 2

// end of lab 2
/*===========================================================================

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
===========================================================================*/
// lab 2

// end of lab 2
/*===========================================================================

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
===========================================================================*/
// lab 3

// end of lab 3
// lab 4

// end of lab 4

// lab 5

// end of lab 5

// lab 6

// end of lab 6

⌨️ 快捷键说明

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