Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

I need to access a server which has html files.
I need to display these files on the handset. http://server.com/a.html

It is similar to the netdiagnostics example app, except that the files are on a server instead of being local.

Does anyone have any example showing how this is done??? I am guessing that ISHELL_BROWSEURL would have to be used.

Thanks in advance.

These are the functions I use to do that.
static boolean Web_GoTo(MyApp *pMe, const char* pszURL)
{
WebCleanup(pMe);
pMe->URL = STRDUP(pszURL);
if (!pMe->URL){
DBGPRINTF("ERROR MEMORY pMe->URL");
return FALSE;
}
if (ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEB, (void **)(&pMe->m_pIWeb)) != SUCCESS){
DBGPRINTF("ERROR CREATING pIWeb");
FREEIF(pMe->URL);
return FALSE;
}
CALLBACK_Init(&pMe->m_Callback, WebReadCB, pMe);
IWEB_GetResponse(pMe->m_pIWeb, (pMe->m_pIWeb, &pMe->m_pIWebResp, &pMe->m_Callback,
pMe->URL,
WEBOPT_HANDLERDATA, pMe,
WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_HEADER, "Content-Type: application/x-www-form-urlencoded\r\n",
WEBOPT_HEADERHANDLER, WebAction_Header,
WEBOPT_METHOD, "POST",
WEBOPT_STATUSHANDLER, WebStatusNotification,
WEBOPT_END));
return TRUE;

// this function used for seeing the web request status
static void WebStatusNotification(void* pNotifyData, WebStatus ws, void* p)
{
MyApp* pMe = (MyApp*)pNotifyData;
switch (ws)
{
case WEBS_CANCELLED:
DBGPRINTF("WEB CANCELLED");
break;
case WEBS_GETHOSTBYNAME:
DBGPRINTF("WEB GET HOST BY NAME, Finding host...");
break;
case WEBS_CONNECT:
DBGPRINTF("WEB CONNECTING");
break;
case WEBS_SENDREQUEST:
DBGPRINTF("WEB SEND REQUEST, sending..%s", pMe->URL);
break;
case WEBS_READRESPONSE:
DBGPRINTF("WEB READ RESPONSE, receiving...%s", pMe->URL);
break;
case WEBS_GOTREDIRECT:
DBGPRINTF("WEB GOT REDIRECT");
break;
case WEBS_CACHEHIT:
DBGPRINTF("WEB CACHE HIT");
break;
}

// this function check if request needs to be redirected
static void WebAction_Header(void* pNotifyData, const char *cpszName, GetLine *pglVal){
MyApp* pMe = (MyApp*)pNotifyData;
if (STRCMP(cpszName, "Location")==0){
pMe->URL_redirect = STRDUP(pglVal->psz);
DBGPRINTF("REDIRECTING TO %s", pMe->URL_redirect);
}

// this functions free memory for the request
static void WebCleanup(Club10 *pMe)
{
if (pMe->URL)
FREEIF(pMe->URL);
CALLBACK_Cancel(&pMe->m_Callback);
if (pMe->m_pIWebResp)
IWEBRESP_Release(pMe->m_pIWebResp);
if (pMe->m_pIWeb)
IWEB_Release(pMe->m_pIWeb);
if (pMe->m_pIHTMLViewer)
IHTMLVIEWER_Release(pMe->m_pIHTMLViewer);
if (pMe->m_BodyBuffer){
FREEIF(pMe->m_BodyBuffer);
pMe->m_BodySize = 0;
pMe->m_BodyAllocSize = 0;
}
}
// with this functions we read the response from the server and if html
// we show it with the HTMLViewer (remember this supports a subset of HTML 3.2)
static void WebReadCB(void* cxt)
{
MyApp* pMe = (MyApp*)cxt;
WebRespInfo* pWebRespInfo = IWEBRESP_GetInfo(pMe->m_pIWebResp);
int ByteCount;
int bsize = 1536;
char buf[bsize];
if (pWebRespInfo){
if (!WEB_ERROR_SUCCEEDED(pWebRespInfo->nCode)){
DBGPRINTF("ERROR NO SUCCESS errcode %d", WEB_ERROR_MAP(pWebRespInfo->nCode));
if (pMe->URL_redirect){
DBGPRINTF("ERROR %s", pMe->URL_redirect);
Web_GoTo(pMe, pMe->URL_redirect);
FREEIF(pMe->URL_redirect);
}
}
else{
ISource* pISource = pWebRespInfo->pisMessage;
ByteCount = ISOURCE_Read(pISource, (char*)buf, sizeof(buf));
// Read() return values fall into four categories of interest:
//
// 1. ISOURCE_WAIT: This means data is not yet available
// 2. ISOURCE_ERROR: An eror occurred
// 3. ISOURCE_END: No more data
// 4. >0 : The actual data that was read
switch (ByteCount)
{
case ISOURCE_WAIT:
DBGPRINTF("ISOURCE WAITING...");
ISOURCE_Readable(pISource, &pMe->m_Callback);
return;
case ISOURCE_ERROR:
// Connection hosed.
DBGPRINTF("ISOURCE ERROR.");
WebCleanup(pMe);
break;
case ISOURCE_END:{
DBGPRINTF("REQUEST SUCCESS");
if (pMe->m_BodySize < pMe->m_BodyAllocSize)
pMe->m_BodyBuffer[pMe->m_BodySize] = 0;
else
pMe->m_BodyBuffer[pMe->m_BodyAllocSize - 1] = 0;
if (pWebRespInfo->cpszContentType){
DBGPRINTF("Content Type %s", pWebRespInfo->cpszContentType);
if (STRBEGINS("text/html", pWebRespInfo->cpszContentType)){
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_HTML, (void**)(&pMe->m_pIHTMLViewer)) != SUCCESS){
return;
}
// Set callback for HTML viewer
IHTMLVIEWER_SetNotifyFn(pMe->m_pIHTMLViewer, (PFNHVIEWNOTIFY)Web_NotifyCB, pMe);
IHTMLVIEWER_SetProperties(pMe->m_pIHTMLViewer, HVP_SCROLLBAR);
IHTMLVIEWER_SetData(pMe->m_pIHTMLViewer, pMe->m_BodyBuffer, -1);
IHTMLVIEWER_SetRect(pMe->m_pIHTMLViewer, &pMe->m_rc);
IHTMLVIEWER_SetActive( pMe->m_pIHTMLViewer, TRUE );
break;
}
}
WebCleanup(pMe);
break;
}
default:
if (ByteCount){
if (pMe->m_BodySize + ByteCount > pMe->m_BodyAllocSize) {
const int NewSize = pMe->m_BodyAllocSize + 1536;
char* NewBuf = (char*)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->m_Callback);
return;
}
}
}

// in this function you can catch events from the HTMLViewer
static void Web_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
MyApp* pMe = (MyApp*) pvUser;
switch( pNotify->code )
{
case HVN_REDRAW_SCREEN:
DBGPRINTF("NOTIFY CALLBACK -> HVN_REDRAW_SCREEN");
break;
case HVN_JUMP:
{
DBGPRINTF("NOTIFY CALLBACK -> HVN_JUMP");
Web_GoTo(pMe, pNotify->u.jump.pszURL);
break;
}
case HVN_SUBMIT:{
DBGPRINTF("NOTIFY CALLBACK -> HVN_SUBMIT");
DBGPRINTF(" submit method %s", pNotify->u.submit.pszMethod);
DBGPRINTF(" submit data %s", pNotify->u.submit.pszData);
Web_GoTo(pMe, pNotify->u.submit.pszURL);
break;
}
case HVN_DONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_DONE");
case HVN_PAGEDONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_PAGEDONE");
case HVN_CONTENTDONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_CONTENTDONE");
IHTMLVIEWER_SetRect(pMe->m_pIHTMLViewer, &pMe->m_rc);
IHTMLVIEWER_Redraw(pMe->m_pIHTMLViewer);
DBGPRINTF("HVN_DONE done loading (nDone = SUCCESS or ERROR)");
break;
}

The variables in pMe should be declared on your app structure.
To make a request just call Web_GoTo(pMe, "http://lalala.lala/lala");

These are the functions I use to do that.
static boolean Web_GoTo(MyApp *pMe, const char* pszURL)
{
WebCleanup(pMe);
pMe->URL = STRDUP(pszURL);
if (!pMe->URL){
DBGPRINTF("ERROR MEMORY pMe->URL");
return FALSE;
}
if (ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEB, (void **)(&pMe->m_pIWeb)) != SUCCESS){
DBGPRINTF("ERROR CREATING pIWeb");
FREEIF(pMe->URL);
return FALSE;
}
CALLBACK_Init(&pMe->m_Callback, WebReadCB, pMe);
IWEB_GetResponse(pMe->m_pIWeb, (pMe->m_pIWeb, &pMe->m_pIWebResp, &pMe->m_Callback,
pMe->URL,
WEBOPT_HANDLERDATA, pMe,
WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_HEADER, "Content-Type: application/x-www-form-urlencoded\r\n",
WEBOPT_HEADERHANDLER, WebAction_Header,
WEBOPT_METHOD, "POST",
WEBOPT_STATUSHANDLER, WebStatusNotification,
WEBOPT_END));
return TRUE;

// this function used for seeing the web request status
static void WebStatusNotification(void* pNotifyData, WebStatus ws, void* p)
{
MyApp* pMe = (MyApp*)pNotifyData;
switch (ws)
{
case WEBS_CANCELLED:
DBGPRINTF("WEB CANCELLED");
break;
case WEBS_GETHOSTBYNAME:
DBGPRINTF("WEB GET HOST BY NAME, Finding host...");
break;
case WEBS_CONNECT:
DBGPRINTF("WEB CONNECTING");
break;
case WEBS_SENDREQUEST:
DBGPRINTF("WEB SEND REQUEST, sending..%s", pMe->URL);
break;
case WEBS_READRESPONSE:
DBGPRINTF("WEB READ RESPONSE, receiving...%s", pMe->URL);
break;
case WEBS_GOTREDIRECT:
DBGPRINTF("WEB GOT REDIRECT");
break;
case WEBS_CACHEHIT:
DBGPRINTF("WEB CACHE HIT");
break;
}

// this function check if request needs to be redirected
static void WebAction_Header(void* pNotifyData, const char *cpszName, GetLine *pglVal){
MyApp* pMe = (MyApp*)pNotifyData;
if (STRCMP(cpszName, "Location")==0){
pMe->URL_redirect = STRDUP(pglVal->psz);
DBGPRINTF("REDIRECTING TO %s", pMe->URL_redirect);
}

// this functions free memory for the request
static void WebCleanup(Club10 *pMe)
{
if (pMe->URL)
FREEIF(pMe->URL);
CALLBACK_Cancel(&pMe->m_Callback);
if (pMe->m_pIWebResp)
IWEBRESP_Release(pMe->m_pIWebResp);
if (pMe->m_pIWeb)
IWEB_Release(pMe->m_pIWeb);
if (pMe->m_pIHTMLViewer)
IHTMLVIEWER_Release(pMe->m_pIHTMLViewer);
if (pMe->m_BodyBuffer){
FREEIF(pMe->m_BodyBuffer);
pMe->m_BodySize = 0;
pMe->m_BodyAllocSize = 0;
}
}
// with this functions we read the response from the server and if html
// we show it with the HTMLViewer (remember this supports a subset of HTML 3.2)
static void WebReadCB(void* cxt)
{
MyApp* pMe = (MyApp*)cxt;
WebRespInfo* pWebRespInfo = IWEBRESP_GetInfo(pMe->m_pIWebResp);
int ByteCount;
int bsize = 1536;
char buf[bsize];
if (pWebRespInfo){
if (!WEB_ERROR_SUCCEEDED(pWebRespInfo->nCode)){
DBGPRINTF("ERROR NO SUCCESS errcode %d", WEB_ERROR_MAP(pWebRespInfo->nCode));
if (pMe->URL_redirect){
DBGPRINTF("ERROR %s", pMe->URL_redirect);
Web_GoTo(pMe, pMe->URL_redirect);
FREEIF(pMe->URL_redirect);
}
}
else{
ISource* pISource = pWebRespInfo->pisMessage;
ByteCount = ISOURCE_Read(pISource, (char*)buf, sizeof(buf));
// Read() return values fall into four categories of interest:
//
// 1. ISOURCE_WAIT: This means data is not yet available
// 2. ISOURCE_ERROR: An eror occurred
// 3. ISOURCE_END: No more data
// 4. >0 : The actual data that was read
switch (ByteCount)
{
case ISOURCE_WAIT:
DBGPRINTF("ISOURCE WAITING...");
ISOURCE_Readable(pISource, &pMe->m_Callback);
return;
case ISOURCE_ERROR:
// Connection hosed.
DBGPRINTF("ISOURCE ERROR.");
WebCleanup(pMe);
break;
case ISOURCE_END:{
DBGPRINTF("REQUEST SUCCESS");
if (pMe->m_BodySize < pMe->m_BodyAllocSize)
pMe->m_BodyBuffer[pMe->m_BodySize] = 0;
else
pMe->m_BodyBuffer[pMe->m_BodyAllocSize - 1] = 0;
if (pWebRespInfo->cpszContentType){
DBGPRINTF("Content Type %s", pWebRespInfo->cpszContentType);
if (STRBEGINS("text/html", pWebRespInfo->cpszContentType)){
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_HTML, (void**)(&pMe->m_pIHTMLViewer)) != SUCCESS){
return;
}
// Set callback for HTML viewer
IHTMLVIEWER_SetNotifyFn(pMe->m_pIHTMLViewer, (PFNHVIEWNOTIFY)Web_NotifyCB, pMe);
IHTMLVIEWER_SetProperties(pMe->m_pIHTMLViewer, HVP_SCROLLBAR);
IHTMLVIEWER_SetData(pMe->m_pIHTMLViewer, pMe->m_BodyBuffer, -1);
IHTMLVIEWER_SetRect(pMe->m_pIHTMLViewer, &pMe->m_rc);
IHTMLVIEWER_SetActive( pMe->m_pIHTMLViewer, TRUE );
break;
}
}
WebCleanup(pMe);
break;
}
default:
if (ByteCount){
if (pMe->m_BodySize + ByteCount > pMe->m_BodyAllocSize) {
const int NewSize = pMe->m_BodyAllocSize + 1536;
char* NewBuf = (char*)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->m_Callback);
return;
}
}
}

// in this function you can catch events from the HTMLViewer
static void Web_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
MyApp* pMe = (MyApp*) pvUser;
switch( pNotify->code )
{
case HVN_REDRAW_SCREEN:
DBGPRINTF("NOTIFY CALLBACK -> HVN_REDRAW_SCREEN");
break;
case HVN_JUMP:
{
DBGPRINTF("NOTIFY CALLBACK -> HVN_JUMP");
Web_GoTo(pMe, pNotify->u.jump.pszURL);
break;
}
case HVN_SUBMIT:{
DBGPRINTF("NOTIFY CALLBACK -> HVN_SUBMIT");
DBGPRINTF(" submit method %s", pNotify->u.submit.pszMethod);
DBGPRINTF(" submit data %s", pNotify->u.submit.pszData);
Web_GoTo(pMe, pNotify->u.submit.pszURL);
break;
}
case HVN_DONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_DONE");
case HVN_PAGEDONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_PAGEDONE");
case HVN_CONTENTDONE:
DBGPRINTF("NOTIFY CALLBACK -> HVN_CONTENTDONE");
IHTMLVIEWER_SetRect(pMe->m_pIHTMLViewer, &pMe->m_rc);
IHTMLVIEWER_Redraw(pMe->m_pIHTMLViewer);
DBGPRINTF("HVN_DONE done loading (nDone = SUCCESS or ERROR)");
break;
}

The variables in pMe should be declared on your app structure.
To make a request just call Web_GoTo(pMe, "http://lalala.lala/lala");

Thanks that is awesome.

Thanks that is awesome.

mmm... I don't really know, I have also done it in the EVT_APP_START and it works ok.
May be the mif file is the problem... In the mif editor, on dependencies try adding the MDN class to your mif and try it again. Hope this helps, since this could be the only difference between our mif files.
Good Luck,
GeRmAn

mmm... I don't really know, I have also done it in the EVT_APP_START and it works ok.
May be the mif file is the problem... In the mif editor, on dependencies try adding the MDN class to your mif and try it again. Hope this helps, since this could be the only difference between our mif files.
Good Luck,
GeRmAn

What is the MDN class?

What is the MDN class?

What is the external class directory to use in order to display the list of classes to search from?? I use the sdk base directory and dont see any classes to choose from.

What is the external class directory to use in order to display the list of classes to search from?? I use the sdk base directory and dont see any classes to choose from.

this is the one i use
C:\Program Files\BREW 3.1.2\sdk\inc

this is the one i use
C:\Program Files\BREW 3.1.2\sdk\inc

I am trying to debug why the webpage wont display.
In ISOURCE_END , the m_bodybuffer has the complete webpage that I need. After IHTML_VIEWER statements nothing happens. Should it display the webpage at this point??
Or is it those MDN class that is preventing it from being displayed. I checked the roadwarrior example accompanying the sdk, it doesnt need those 3 statements.
I am almost there, just need to get the final piece working to display the webpage.

I am trying to debug why the webpage wont display.
In ISOURCE_END , the m_bodybuffer has the complete webpage that I need. After IHTML_VIEWER statements nothing happens. Should it display the webpage at this point??
Or is it those MDN class that is preventing it from being displayed. I checked the roadwarrior example accompanying the sdk, it doesnt need those 3 statements.
I am almost there, just need to get the final piece working to display the webpage.

Adding the MDN class id didnt help. Uncommenting those lines doesnt work. Do I need those lines to display the webpage?

Adding the MDN class id didnt help. Uncommenting those lines doesnt work. Do I need those lines to display the webpage?

Then it's probably not :)
What kind of webpage is hello.htm? If it's not quite big could you post the code of it?

Then it's probably not :)
What kind of webpage is hello.htm? If it's not quite big could you post the code of it?

enclosing my complete program

enclosing my complete program

here is the webpage hello.htm
Main Menu
link1
link2
help
about

here is the webpage hello.htm
Main Menu
link1
link2
help
about

sorry i was refering to the html file :)

sorry i was refering to the html file :)

mmm... strange... the html file seems to be ok...
I'll take a look at your code...

mmm... strange... the html file seems to be ok...
I'll take a look at your code...

looking at your code, the only thing I found that could be a reason of why it doesn't display is that pMe->m_rc is not initialized...
Before doing
Web_GoTo(pMe, "http://myserver.xxx.com/nd_mainmenu.htm");
on the EVT_APP_START of the handle_event you should put this code:
AEEDeviceInfo di;
// Get device screen rect
ISHELL_GetDeviceInfo(pMe->a.m_pIShell, &di);
SETAEERECT(&pMe->m_rc, 0, 0, di.cxScreen, di.cyScreen);
hope this works!

looking at your code, the only thing I found that could be a reason of why it doesn't display is that pMe->m_rc is not initialized...
Before doing
Web_GoTo(pMe, "http://myserver.xxx.com/nd_mainmenu.htm");
on the EVT_APP_START of the handle_event you should put this code:
AEEDeviceInfo di;
// Get device screen rect
ISHELL_GetDeviceInfo(pMe->a.m_pIShell, &di);
SETAEERECT(&pMe->m_rc, 0, 0, di.cxScreen, di.cyScreen);
hope this works!

After the initial webpage html is displayed, up and down keys are not working to go up and down on the webpage. How can I do this? Should I let the HTMLVIEWER handle those events. and how can i launch subsequent pages.

After the initial webpage html is displayed, up and down keys are not working to go up and down on the webpage. How can I do this? Should I let the HTMLVIEWER handle those events. and how can i launch subsequent pages.

The webnotify function like the netdiagnostics example doesnt seem to work to scroll through the links and surf subsequent pages. Any ideas??

The webnotify function like the netdiagnostics example doesnt seem to work to scroll through the links and surf subsequent pages. Any ideas??