📄 myiweb.step2
字号:
// 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
if(pMe->m_pIStatic)
{
ISTATIC_Release(pMe->m_pIStatic);
pMe->m_pIStatic = NULL;
}
// 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
static void myiweb_DisplayInfo(myiweb* pMe,AECHAR* pInfo)
{
AEERect rct;
if(!pMe->m_pIStatic)
ISHELL_CreateInstance(pMe->pIShell, AEECLSID_STATIC, (void **)&pMe->m_pIStatic);
SETAEERECT(&rct, 16, 16, pMe->DeviceInfo.cxScreen-32, pMe->DeviceInfo.cyScreen-32);
ISTATIC_SetRect(pMe->m_pIStatic, &rct);
ISTATIC_SetText(pMe->m_pIStatic, NULL,pInfo, AEE_FONT_BOLD, AEE_FONT_NORMAL);
ISTATIC_Redraw(pMe->m_pIStatic);
}
// 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
WEBOPT_HEADERHANDLER, myiweb_Header,
WEBOPT_STATUSHANDLER, myiweb_Status,
// 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
WEBOPT_HEADERHANDLER, myiweb_Header,
WEBOPT_STATUSHANDLER, myiweb_Status,
//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
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);
// }
}
// 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
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);
}
}
// 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 + -