void CMainFrame::MakeIndex()
{
//assumes server, port and URL names have been initialized
CInternetSession session("www.ecoln.com Cambridgeshire Search");
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString strServerName;
m_wndDlgBar.GetDlgItem(IDC_EADDRESS)->GetWindowText(strServerName);
//AfxMessageBox(strServerName);
if (strServerName.GetLength() > 7)
{
CString tempStr = strServerName.Left(7);
tempStr.MakeLower();
if ( tempStr == "http://")
{
strServerName = strServerName.Right (strServerName.GetLength() -7);
}
}
INTERNET_PORT nPort = 80;
CString strObject = "";
DWORD dwRet = 0;
char szBuff[1023];
CString myString;
int slashPos = strServerName.FindOneOf ("/");
int strLen = strServerName.GetLength();
if (slashPos < strLen - 1)
strObject = strServerName.Right (strLen - slashPos - 1);
if (slashPos > -1)
strServerName = strServerName.Left (slashPos);
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
if (dwRet == HTTP_STATUS_OK)
{
TCHAR sz[1024];
int nRead = 1024;
while (nRead > 0)
{
nRead = pFile->Read(sz, 1023);
sz[nRead] = '\0';
myString = myString + (CString)sz ;
}
_largeWordMapClassPtr pDLL("ECOLNIndexMod.LargeWordMapClass");
//See article an 'VARIANT and VARIANTARG' from 'Automation: Platform SDK'
//myString = strServerName + "\\" + strObject;
_variant_t myHTMLSource (myString);
pDLL->initializeStuff();
//ShowDialog.m_strShowText = myString = strServerName + "/" + strObject + "\n";
//20020718
int eqPos = 0;
while (eqPos >= 0){
eqPos = strObject.Find('=',eqPos);
int strObLen = strObject.GetLength();
if (eqPos >= 0){
CString rPart = strObject.Right (strObLen - eqPos -1);
CString lPart = strObject.Left (eqPos);
strObject = lPart + "%3d" + rPart;
eqPos = eqPos + 3;
}
}
myString = "ixurl=" + strServerName + "/" + strObject + "\r\n";
ShowDialog.m_strShowText = myString;
ShowDialog.m_strURL = strServerName + "/" + strObject;
ShowDialog.m_strShowText = ShowDialog.m_strShowText +
(CString)(char *) pDLL->makeList(&myHTMLSource.bstrVal);
ShowDialog.m_strURL = strServerName + "/" + strObject;
ShowDialog.m_unsHTMLSrc = &myHTMLSource.bstrVal;
UpdateData(FALSE);
ShowDialog.DoModal();
}
else {AfxMessageBox("Download failed at index point \r\n" + (CString)szHeaders);}
delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
AfxMessageBox("Download failed on WinInet exception \r\n" + (CString)szHeaders);
}
session.Close();
}
|