//use this function to update any status, edit or what ever control
//that needs updating
void CMyInternetSession::ShowStatus(LPCTSTR strStatus)
{
CGetWebFileDlg * pWebFileDlg = (CGetWebFileDlg*) AfxGetMainWnd();
pWebFileDlg->ShowStatus(strStatus);
}
//Lets get the file via http
DWORD CMyInternetSession::GetWebFile(LPCTSTR pstrAgent, LPCTSTR lpstrServer, int nPort, CString strFile)
{
//Check what file types we will allow to be requested
CString extension = strFile.Right(3);
/*string containing the application name that is used to refer
client making the request. If this NULL the frame work will
call the global function AfxGetAppName which returns the application
name.*/
//LPCTSTR pstrAgent = NULL;
//the verb we will be using for this connection
//if NULL then GET is assumed
LPCTSTR pstrVerb = "GET";
//the address of the url in the request was obtained from
LPCTSTR pstrReferer = NULL;
//Http version we are using; NULL = HTTP/1.0
LPCTSTR pstrVersion = NULL;
//For the Accept request headers if we need them later on
//LPCTSTR pstrAcceptTypes = "Accept: audio/x-aiff, audio/basic, audio/midi, audio/mpeg, audio/wav, image/jpeg, image/gif, image/jpg, image/png, image/mng, image/bmp, text/plain, text/html, text/htm\r\n";
LPCTSTR pstrAcceptTypes = NULL;
CString szHeaders = "Accept: audio/x-aiff, audio/basic, audio/midi, audio/mpeg, audio/wav, image/jpeg, image/gif, image/jpg, image/png, image/mng, image/bmp, text/plain, text/html, text/htm\r\n";
//the server port we need changed
//nPort = INTERNET_INVALID_PORT_NUMBER
unsigned short usPort = nPort;
//Username we will use if a secure site comes into play
LPCTSTR pstrUserName = NULL;
//The password we will use
LPCTSTR pstrPassword = NULL;
//CInternetSession flags if we need them
//DWORD dwFlags = INTERNET_FLAG_ASYNC;
DWORD dwFlags = NULL;
//Proxy setting if we need them
LPCTSTR pstrProxyName = NULL;
LPCTSTR pstrProxyBypass = NULL;
//Set any CInternetSession options we may need
int ntimeOut = 30;
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,1000* ntimeOut);
session.SetOption(INTERNET_OPTION_CONNECT_BACKOFF,1000);
session.SetOption(INTERNET_OPTION_CONNECT_RETRIES,1);
//Enable or disable status callbacks
session.EnableStatusCallback(TRUE);
if (dwRet == HTTP_STATUS_DENIED)
{
return dwRet;
}
if (dwRet == HTTP_STATUS_MOVED ||
dwRet == HTTP_STATUS_REDIRECT ||
dwRet == HTTP_STATUS_REDIRECT_METHOD)
{
CString strNewAddress;
//again check wininet.h for info on the query info codes
//there is alot one can do and re-act to based on these codes
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewAddress);
int nPos = strNewAddress.Find(_T("Location: "));
if (nPos == -1)
{
return 0;
}
strNewAddress = strNewAddress.Mid(nPos + 10);
nPos = strNewAddress.Find('\n');
if (nPos > 0)
strNewAddress = strNewAddress.Left(nPos);
switch (dwInternetStatus)
{
case INTERNET_STATUS_RESOLVING_NAME:
strStatus.Format("Resolving name %s", lpvStatusInformation);
break;
case INTERNET_STATUS_NAME_RESOLVED:
strStatus.Format("Name resolved %s", lpvStatusInformation);
break;
case INTERNET_STATUS_HANDLE_CREATED:
strStatus.Format("Handle created");
break;
case INTERNET_STATUS_CONNECTING_TO_SERVER:
strStatus.Format("Connecting to socket address");
break;
case INTERNET_STATUS_CONNECTED_TO_SERVER:
strStatus.Format("Connected to socket address");
break;
case INTERNET_STATUS_SENDING_REQUEST:
strStatus.Format("Sending request");
break;
case INTERNET_STATUS_REQUEST_SENT:
strStatus.Format("Request sent");
break;
case INTERNET_STATUS_RECEIVING_RESPONSE:
return;
strStatus.Format("Receiving response");
break;
case INTERNET_STATUS_RESPONSE_RECEIVED:
strStatus.Format("Response received");
break;
case INTERNET_STATUS_CLOSING_CONNECTION:
strStatus.Format("Closing the connection to the server");
break;
case INTERNET_STATUS_CONNECTION_CLOSED:
strStatus.Format("Connection to the server closed");
break;
case INTERNET_STATUS_HANDLE_CLOSING:
return;
strStatus.Format("Handle closed");
break;
//Check MSDN information about CInternetSession dwFlag INTERNET_FLAG_ASYNC
//I have never been able to get this to work to my liking
case INTERNET_STATUS_REQUEST_COMPLETE:
strStatus.Format("Request complete");
break;
case INTERNET_STATUS_REDIRECT:
strStatus.Format("Being redirected");
break;