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

Developer

Forums

Forums:

Hi,

I can connect to a indirect http address, and it has a "real" direct http link where I can download a cilp. How do I get the direct link off the TCP stream? I can handle direct link, but indirect link is a problem for me. How do I do this? something to do with IWEB_GetResponse, right? A code drop would be helpful.
Thank you.

Included is the TCP stream. What do I do with it? I only need to get the LOCATION tag in there. I found WEBREQUEST_REDIRECT, but it's not implemented, does that mean BREW doesn't support http redirect?

anybody knows about this? Thanks.

anybody knows about this? Thanks.

IWeb will receive the 3xx code in the WebRespInfo's nCode variable (which can be accessd by calling IWEBRESP_GetInfo() in your IWEB_GetResponse()'s callback).
Some 3xx codes contain a "Location" header (not all 3xx are redirects...). So if you have used the WEBOPT_HEADERHANDLER (registered a header parsing function) in you IWEB_GetResponse() call, your application will see "Location" header if the server offers it for the response. Those applications can then fetch the redirected URL (if appropriate) and thus implement a redirect.
The redirection URL might also be in the body, but no IWEB client should ever depend on it (it's non-standard). If it does appear, it's merely a convenience for browsers that don't handle 3xx+Location header (the user can click though a hypertext link instead).

IWeb will receive the 3xx code in the WebRespInfo's nCode variable (which can be accessd by calling IWEBRESP_GetInfo() in your IWEB_GetResponse()'s callback).
Some 3xx codes contain a "Location" header (not all 3xx are redirects...). So if you have used the WEBOPT_HEADERHANDLER (registered a header parsing function) in you IWEB_GetResponse() call, your application will see "Location" header if the server offers it for the response. Those applications can then fetch the redirected URL (if appropriate) and thus implement a redirect.
The redirection URL might also be in the body, but no IWEB client should ever depend on it (it's non-standard). If it does appear, it's merely a convenience for browsers that don't handle 3xx+Location header (the user can click though a hypertext link instead).

tamoghna wrote:IWeb will receive the 3xx code in the WebRespInfo's nCode variable (which can be accessd by calling IWEBRESP_GetInfo() in your IWEB_GetResponse()'s callback).
Some 3xx codes contain a "Location" header (not all 3xx are redirects...). So if you have used the WEBOPT_HEADERHANDLER (registered a header parsing function) in you IWEB_GetResponse() call, your application will see "Location" header if the server offers it for the response. Those applications can then fetch the redirected URL (if appropriate) and thus implement a redirect.
The redirection URL might also be in the body, but no IWEB client should ever depend on it (it's non-standard). If it does appear, it's merely a convenience for browsers that don't handle 3xx+Location header (the user can click though a hypertext link instead).
Thank you for your reply.
Yes, it is inside the return message, LOCATION tag. How do I get to it? I know WebRespInfo contains some info, but pWebRespInfo->pisMessage is not the return message, right, it is the message for returned data to be accessed?
So, I guess IWEB_GetResponse() should look like this, right?
IWEB_GetResponse(pApp->m_pIWeb,(pApp->m_pIWeb, &pApp->m_pIWebResp, &pApp->m_Callback,pApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADERHANDLER, ???, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_END));
What is a good header parsing function? Do we have to implement by ourselves? Could you give me an example, SetLocationAsURL()?
Thank you. I'm really new to this..

tamoghna wrote:IWeb will receive the 3xx code in the WebRespInfo's nCode variable (which can be accessd by calling IWEBRESP_GetInfo() in your IWEB_GetResponse()'s callback).
Some 3xx codes contain a "Location" header (not all 3xx are redirects...). So if you have used the WEBOPT_HEADERHANDLER (registered a header parsing function) in you IWEB_GetResponse() call, your application will see "Location" header if the server offers it for the response. Those applications can then fetch the redirected URL (if appropriate) and thus implement a redirect.
The redirection URL might also be in the body, but no IWEB client should ever depend on it (it's non-standard). If it does appear, it's merely a convenience for browsers that don't handle 3xx+Location header (the user can click though a hypertext link instead).
Thank you for your reply.
Yes, it is inside the return message, LOCATION tag. How do I get to it? I know WebRespInfo contains some info, but pWebRespInfo->pisMessage is not the return message, right, it is the message for returned data to be accessed?
So, I guess IWEB_GetResponse() should look like this, right?
IWEB_GetResponse(pApp->m_pIWeb,(pApp->m_pIWeb, &pApp->m_pIWebResp, &pApp->m_Callback,pApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADERHANDLER, ???, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_END));
What is a good header parsing function? Do we have to implement by ourselves? Could you give me an example, SetLocationAsURL()?
Thank you. I'm really new to this..

Your WEBOPT_HEADERHANDLER function can be
eg:
static void HeaderHandler(MyApp *pApp, const char *cpszName, GetLine *pglVal)
which will receive
cpszName: the name of the web header ("Location")
pglVal: the value of the header, like (The URL).
Here, collect the URL in an applet member variable for later use.
Then in your IWEB_GetResponse()'s response handler ( &pApp->m_pIWebResp in your case ) check for nCode (in WebRespInfo) for 3xx code and implement appropriate function calls to call IWEB_GetResponse() with the URL you have collected from the header.

Your WEBOPT_HEADERHANDLER function can be
eg:
static void HeaderHandler(MyApp *pApp, const char *cpszName, GetLine *pglVal)
which will receive
cpszName: the name of the web header ("Location")
pglVal: the value of the header, like (The URL).
Here, collect the URL in an applet member variable for later use.
Then in your IWEB_GetResponse()'s response handler ( &pApp->m_pIWebResp in your case ) check for nCode (in WebRespInfo) for 3xx code and implement appropriate function calls to call IWEB_GetResponse() with the URL you have collected from the header.

tamoghna wrote:Your WEBOPT_HEADERHANDLER function can be
eg:
static void HeaderHandler(MyApp *pApp, const char *cpszName, GetLine *pglVal)
which will receive
cpszName: the name of the web header ("Location")
pglVal: the value of the header, like (The URL).
Here, collect the URL in an applet member variable for later use.
Then in your IWEB_GetResponse()'s response handler ( &pApp->m_pIWebResp in your case ) check for nCode (in WebRespInfo) for 3xx code and implement appropriate function calls to call IWEB_GetResponse() with the URL you have collected from the header.
Thank you, you are very helpful.
I found that WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal) is in the Netdiagnostics example, but it's too simple. I need to implement some sort of search in there, right? How do I do that (searching for cpszName = Location, return url)? I guess url is pglVal->psz, right?
Some code samples would help.
After that, I IWebResponse should be:
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_HEADERHANDLER, url, WEBOPT_END));
Is this right? Or, do I need to get another IWEB_GetResponse()?
Thank you very much.

tamoghna wrote:Your WEBOPT_HEADERHANDLER function can be
eg:
static void HeaderHandler(MyApp *pApp, const char *cpszName, GetLine *pglVal)
which will receive
cpszName: the name of the web header ("Location")
pglVal: the value of the header, like (The URL).
Here, collect the URL in an applet member variable for later use.
Then in your IWEB_GetResponse()'s response handler ( &pApp->m_pIWebResp in your case ) check for nCode (in WebRespInfo) for 3xx code and implement appropriate function calls to call IWEB_GetResponse() with the URL you have collected from the header.
Thank you, you are very helpful.
I found that WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal) is in the Netdiagnostics example, but it's too simple. I need to implement some sort of search in there, right? How do I do that (searching for cpszName = Location, return url)? I guess url is pglVal->psz, right?
Some code samples would help.
After that, I IWebResponse should be:
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_HEADERHANDLER, url, WEBOPT_END));
Is this right? Or, do I need to get another IWEB_GetResponse()?
Thank you very much.

mzichao wrote:Thank you, you are very helpful.
I found that WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal) is in the Netdiagnostics example, but it's too simple. I need to implement some sort of search in there, right? How do I do that (searching for cpszName = Location, return url)? I guess url is pglVal->psz, right?
Some code samples would help.
After that, I IWebResponse should be:
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_HEADERHANDLER, url, WEBOPT_END));
Is this right? Or, do I need to get another IWEB_GetResponse()?
Thank you very much.
pglVal->psz will hold the url.
I think your are confused at one point.
Suppose xyz.com was the url you first used with IWEB_GetRespone(), then as explained above, you will have 2 (atleast, incase u have others) callbacks firing.
1. is the HEADERHANDLER callback, where you get the redirect URL (say abc.com) and
2. the IWEB_GetResponse() registered callback -> that is the callback you have initiated for &pApp->m_pIWebResp . Here you check for nCode and suitably call IWEB_GetResponse() again with the redicrect url.
I hope this clears your confusion.

mzichao wrote:Thank you, you are very helpful.
I found that WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal) is in the Netdiagnostics example, but it's too simple. I need to implement some sort of search in there, right? How do I do that (searching for cpszName = Location, return url)? I guess url is pglVal->psz, right?
Some code samples would help.
After that, I IWebResponse should be:
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",WEBOPT_HEADERHANDLER, url, WEBOPT_END));
Is this right? Or, do I need to get another IWEB_GetResponse()?
Thank you very much.
pglVal->psz will hold the url.
I think your are confused at one point.
Suppose xyz.com was the url you first used with IWEB_GetRespone(), then as explained above, you will have 2 (atleast, incase u have others) callbacks firing.
1. is the HEADERHANDLER callback, where you get the redirect URL (say abc.com) and
2. the IWEB_GetResponse() registered callback -> that is the callback you have initiated for &pApp->m_pIWebResp . Here you check for nCode and suitably call IWEB_GetResponse() again with the redicrect url.
I hope this clears your confusion.

Ok, so I need to callbacks and IWEB_GetResponse(), right? like this?
Please look at bold sections, where I need help define. Callbacks don't execute the second part (real URL).
case IDC_CONTENT1:
if (ISHELL_CreateInstance(pApp->m_Applet.m_pIShell, AEECLSID_WEB, (void**)(&pApp->m_Network->m_pIWeb)) != SUCCESS)
{
pApp->m_Network->m_pIWeb = NULL;
WebCleanup(pApp);
return FALSE;

pApp->m_Network->m_BodyBuffer = NULL;
pApp->m_Network->m_BodySize = 0;
pApp->m_Network->m_BodyAllocSize = 0;
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",
WEBOPT_HEADERHANDLER, WebAction_Header,WEBOPT_END));
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,
[b]pApp->m_Network->m_newURL[\b], WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n", WEBOPT_END));
return TRUE;
default:
return FALSE;

break;
Also, in WebAction_Header() function, do I need to do anything special there? I mean, do I need to implement some search?
static void WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal)
{
cpszName = "Location";
pApp->m_Network->m_newURL = pglVal->psz;
???????????????????

Thank you very much

Ok, so I need to callbacks and IWEB_GetResponse(), right? like this?
Please look at bold sections, where I need help define. Callbacks don't execute the second part (real URL).
case IDC_CONTENT1:
if (ISHELL_CreateInstance(pApp->m_Applet.m_pIShell, AEECLSID_WEB, (void**)(&pApp->m_Network->m_pIWeb)) != SUCCESS)
{
pApp->m_Network->m_pIWeb = NULL;
WebCleanup(pApp);
return FALSE;

pApp->m_Network->m_BodyBuffer = NULL;
pApp->m_Network->m_BodySize = 0;
pApp->m_Network->m_BodyAllocSize = 0;
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,pApp->m_CCApp->m_cotentTag[1].downloadURL, WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n",
WEBOPT_HEADERHANDLER, WebAction_Header,WEBOPT_END));
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,
[b]pApp->m_Network->m_newURL[\b], WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n", WEBOPT_END));
return TRUE;
default:
return FALSE;

break;
Also, in WebAction_Header() function, do I need to do anything special there? I mean, do I need to implement some search?
static void WebAction_Header(CatMedia *pApp, const char *cpszName, GetLine *pglVal)
{
cpszName = "Location";
pApp->m_Network->m_newURL = pglVal->psz;
???????????????????

Thank you very much

In your header handler function, it should be
if (cpszName = "Location")
pApp->m_Network->m_newURL = pglVal->psz;
Also, you are not correct in your implementation. Please read my previous post point #2 again.
Just to clarify again ....
You need to call
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,
[b]pApp->m_Network->m_newURL[\b], WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n", WEBOPT_END));
return TRUE;
within the response handler function of your first IWEB_GetResponse. ie. within the callback : &pApp->m_Network->m_Callback
your callback function associated with pApp->m_Network->m_Callback will be called after you are done parsing the header. (i.e. after header handler callback is compltely executed. Note that, this header handler callback is called as many times as there are headers present. Only after all headers are parsed, that the pApp->m_Network->m_Callback will be called.

In your header handler function, it should be
if (cpszName = "Location")
pApp->m_Network->m_newURL = pglVal->psz;
Also, you are not correct in your implementation. Please read my previous post point #2 again.
Just to clarify again ....
You need to call
CALLBACK_Init(&pApp->m_Network->m_Callback, WebReadCB, pApp);
IWEB_GetResponse(pApp->m_Network->m_pIWeb,(pApp->m_Network->m_pIWeb, &pApp->m_Network->m_pIWebResp, &pApp->m_Network->m_Callback,
[b]pApp->m_Network->m_newURL[\b], WEBOPT_HANDLERDATA, pApp, WEBOPT_HEADER, "X-Method: GET\r\n", WEBOPT_END));
return TRUE;
within the response handler function of your first IWEB_GetResponse. ie. within the callback : &pApp->m_Network->m_Callback
your callback function associated with pApp->m_Network->m_Callback will be called after you are done parsing the header. (i.e. after header handler callback is compltely executed. Note that, this header handler callback is called as many times as there are headers present. Only after all headers are parsed, that the pApp->m_Network->m_Callback will be called.

tamoghna,
Thank you very much. I got the problem solved. I wish everybody could be like you, so eager to help. Thanks again. :)

tamoghna,
Thank you very much. I got the problem solved. I wish everybody could be like you, so eager to help. Thanks again. :)