|
From: Martin R. <zo...@us...> - 2005-10-25 20:54:22
|
Update of /cvsroot/nbftools/CellTrack In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26083 Modified Files: CellDB.cpp Global.h LocalDB.cpp Log Message: Fixed some major bugs (poor hashing, bad parsing of HTTP responses, etc) Index: LocalDB.cpp =================================================================== RCS file: /cvsroot/nbftools/CellTrack/LocalDB.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- LocalDB.cpp 25 Oct 2005 16:53:02 -0000 1.11 +++ LocalDB.cpp 25 Oct 2005 20:54:11 -0000 1.12 @@ -8,6 +8,10 @@ #include "Settings.h" #include "Registry.h" +#include "stdafx.h" +#include "log.h" +extern CLog *g_pLog; + extern CSettings *g_pSettings; ////////////////////////////////////////////////////////////////////// @@ -53,7 +57,7 @@ pGroupWork = pGroupStart; pGroupStart = pGroupStart->pNext; - + delete (pGroupWork); } } @@ -364,9 +368,15 @@ { pSearchCell = pCellStart; } - + while (pSearchCell) { + /*CString strTmp; + strTmp.Format(L"Searching cell %d, bSynced = %d, %s", + pSearchCell->CellInfo.ulCellID, pSearchCell->CellInfo.bSynced, pSearchCell->CellInfo.szCellID); + g_pLog->Log(LOG_VERBOSE, strTmp);*/ + + if (!pSearchCell->CellInfo.bSynced) { lRet = pSearchCell->CellInfo.ulCellID; @@ -482,6 +492,19 @@ memset(&CellInfo, 0, sizeof(T_CELLINFO)); fread(&CellInfo, sizeof(T_CELLINFO), 1, pFile); + if(CellInfo.ulCellID < 5000) { + //Old CalculateCellID implemention simply summed the + //characters in szCellID. This resulted in almost all + //hashes being below 5000, and frequent collisions + //(eg.234-33-1254-40958 & 234-33-1254-43748 both had + //checksum = 860). + + //Hashes which could have been generated using the old + //method need to be recalculated. + + CellInfo.ulCellID = CalculateCellID(CellInfo.szCellID); + } + // add the cell - via the load flag AddCellInfo(&CellInfo, false, true); } @@ -579,7 +602,7 @@ for (uiCount = 0; uiCount < uiLen; uiCount ++) { - lRet += (unsigned short) *pStr++; + lRet = ((lRet << 5) ^ (lRet >> 27)) ^ *pStr++; } } @@ -600,7 +623,7 @@ for (uiCount = 0; uiCount < uiLen; uiCount ++) { - lRet += (unsigned short) *pStr++; + lRet = ((lRet << 3) ^ (lRet >> 5)) ^ *pStr++; } bRet = (BYTE) lRet % 255; Index: Global.h =================================================================== RCS file: /cvsroot/nbftools/CellTrack/Global.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Global.h 3 Oct 2005 12:26:29 -0000 1.21 +++ Global.h 25 Oct 2005 20:54:11 -0000 1.22 @@ -9,10 +9,10 @@ #define WM_HSEVENT (WM_USER+1) -#define CELLTRACK_VERSION (TEXT("Beta 8.3")) +#define CELLTRACK_VERSION (TEXT("Beta 8.4")) #define CELLTRACK_VERSION_MAJ (0) #define CELLTRACK_VERSION_MIN (8) -#define CELLTRACK_VERSION_REV (3) +#define CELLTRACK_VERSION_REV (4) #define CT_CELLID_LEN (75) #define CT_USERNAME_LEN (75) Index: CellDB.cpp =================================================================== RCS file: /cvsroot/nbftools/CellTrack/CellDB.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- CellDB.cpp 25 Oct 2005 16:53:02 -0000 1.27 +++ CellDB.cpp 25 Oct 2005 20:54:10 -0000 1.28 @@ -97,6 +97,7 @@ char *pTmp; int i; TCHAR sztLine[255]; + CString strTemp; // sort the headers out for the communication to the internet wsprintf(sztHeaders, L"X-WAP-PROFILE: \"http://wap.sonyericsson.com/UAprof/P800R102.xml\""); @@ -135,6 +136,9 @@ // Read reply from server nRet = InternetReadFile( hURL, sTmp, sizeof(sTmp), &nRxLen ); + + strTemp.Format(L"InternetReadFile returns %d and %d bytes read", nRet, nRxLen); + g_pLog->Log(LOG_DEBUG, strTemp); if (nRet) { @@ -144,46 +148,43 @@ while(*pTmp) { - if(*pTmp != '\r') + if(*pTmp >= ' ') //Not a control character { sztLine[i++] = *pTmp; } - else if(*pTmp == '\n') + + if(*pTmp == '\n') //Finished reading line { - sztLine[i-1] = 0; + sztLine[i] = 0; + + strTemp.Format(L"HTTP Response Line: %s", sztLine); + g_pLog->Log(LOG_DEBUG, strTemp); /*if(_tcsstr(sztLine, _T("SubmitOK"))) { //Submit OK - DWORD dwTemp = 0; - CCellGet::CellStructToIDString(ctLast, sztTmp); - CRegistry::SaveSetting(HKEY_CURRENT_USER, TEXT("SOFTWARE\\SPV-Developers\\CellTrack\\ToSubmit_Cells"), - sztTmp, REG_DWORD, (LPBYTE) &dwTemp); - SetStatus(L"Cell Submitted"); - Sleep(1000); + SetStatus(L"Cell Submitted"); } - if(_tcsstr(sztLine, _T("SubmitGroupOK"))) { //Submit Group OK - DWORD dwTemp = 0; - CCellGet::CellStructToIDString(ctLast, sztTmp); - CRegistry::SaveSetting(HKEY_CURRENT_USER, TEXT("SOFTWARE\\SPV-Developers\\CellTrack\\ToSubmit_Groups"), - sztTmp, REG_DWORD, (LPBYTE) &dwTemp); + if(_tcsstr(sztLine, _T("SubmitGroupOK"))) { //Submit Group OK SetStatus(L"Group Submitted"); - Sleep(1000); - }*/ + }*/ if(_tcsstr(sztLine, _T("OK"))) { - bRet = true; // no data returned + bRet = true; // server understood our request } else if(_tcsstr(sztLine, _T("NA: "))) { //Cell Name - _stprintf(pCellInfo->szLocName, TEXT("%s"), sztLine+8); + _stprintf(pCellInfo->szLocName, TEXT("%s"), sztLine+4); + + strTemp.Format(L"Server sent name '%s' for cell '%s'", pCellInfo->szLocName, pCellInfo->szCellID); + g_pLog->Log(LOG_DEBUG, strTemp); } else if(_tcsstr(sztLine, _T("FN: "))) { //Cell Friendly/Group Name TCHAR szGroupName[CT_GROUPNAME_LEN]; BYTE bGroupID; - _stprintf(szGroupName, TEXT("%s"), sztLine+8); + _stprintf(szGroupName, TEXT("%s"), sztLine+4); // Check to see if group exitst bGroupID = g_pLocalDB->FindGroupID(szGroupName); @@ -200,7 +201,7 @@ else if(_tcsstr(sztLine, _T("MSG:"))) { //Display Message SetStatus(sztLine); - Sleep(1000); + Sleep(2000); } i=0; @@ -211,8 +212,6 @@ InternetCloseHandle(hURL); InternetCloseHandle(hInternet); - - bRet = true; } else { @@ -233,8 +232,10 @@ { if(nRet) { - SetStatus(_T("Success")); - bRet = true; + if(bRet) + SetStatus(_T("Success")); + else + SetStatus(_T("No Confirmation")); } else { @@ -263,7 +264,6 @@ SetStatus(_T("Dialing...")); EstablishConnection(tcTmp); SetStatus(tcTmp); - Sleep(1000); SetStatus(TEXT("Syncing Database")); @@ -328,6 +328,7 @@ // do we want the server overwritting the local DB if (g_pSettings->GetCellDBOveride()) { + g_pLog->Log(LOG_DEBUG, L"Overwriting local CellDB entry with remote one"); g_pLocalDB->AddCellInfo(&CellInfo, true); } @@ -342,18 +343,16 @@ } SetStatus(_T("Disconnect...")); - Sleep(500); if(phWebConnection) { ConnMgrReleaseConnection(phWebConnection, false); phWebConnection = NULL; SetStatus(_T("HangedUp")); - Sleep(1000); } SetStatus(TEXT("Sync Complete")); - Sleep(500); + Sleep(1000); return (hr); } @@ -531,7 +530,7 @@ { _tcscpy(m_pszStatus, sts); g_pLog->Log(LOG_DEBUG, sts); - Sleep(300); + Sleep(1000); //1 sec minimum, as status message is refreshed every second } //----------------------------------------------------------------------------- |