Example #1
0
Tuple::Tuple(const char *fmt, ...){
  va_list ap;
  va_start(ap, fmt);
  _buildTuple(fmt, ap);
  va_end(ap);

#ifdef CHECK_INTEGRITY
  this->_sum = computeCheckSum(); 
#endif

}
/*!
   Computes the Random number based on current system time
   
   @return int Returns the generated random number
 */
int WpsPageStepThreeNumber::computeRandNumber()
{
    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this);

    int pin = 0;
    QTime time(0, 0);
    int seed = time.secsTo(QTime::currentTime());
    
    do {
        qsrand(seed);
        pin = qrand();
    } while (pin < (10 ^ (KMaxPINLength - 2)) || (((pin / 1000000) % 10)) == 0);
    
    //last digit is checksum, so we need 7 digits
    //and the first shouldn't be 0
    pin = pin % 10000000;
    int checkSum = computeCheckSum(pin);
    pin *= 10;
    pin += checkSum;
    
    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this);
    return pin;
}
BOOL CComputeCheckSum::getCheckSum(CString& omStrConfigFileName,
                                    UCHAR* pucCheckSum, UCHAR* pucCheckSumInFile)
{
    CStdioFile omStdiofile;
    CFileException   omException  ;
    DWORD dwSize                 = 0;
    DWORD dwRead                 = 0;
    BOOL bReturn                 = FALSE;
    BOOL bFileOpen               = FALSE;
    CString omStrErrorMessage    = "";
    char  acErrorMsg[defSIZE_OF_ERROR_BUFFER];
    // Open the configration file.
    TRY
    {
        bFileOpen = omStdiofile.Open(omStrConfigFileName,
        CFile::modeRead | CFile::typeBinary, &omException);
        if(bFileOpen!=FALSE)
        {
            UCHAR* pucBuff   = NULL;
            // Get the size of file
            dwSize = (DWORD)omStdiofile.GetLength();
            if( dwSize > 0)
            {
                pucBuff = static_cast<UCHAR*> (new UCHAR[dwSize]);
                if(pucBuff!=NULL)
                {
                    // Read the whole file and put the content to pucBuff;
                    dwRead = omStdiofile.Read(pucBuff,dwSize);
                    // Compute the checksum
                    bReturn = computeCheckSum(pucBuff,dwSize - 1,
                    pucCheckSum);
                    // Get the check sum stored in file ( Last byte )
                    *pucCheckSumInFile  = pucBuff[dwSize-1];
                    delete [] pucBuff;
                    pucBuff = NULL;
                }
            }
            omStdiofile.Close();
            bReturn = TRUE;
        }
        else
        {

            // Get the exception error message
            omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
            // configuration file  open error notification
            //AfxMessageBox(acErrorMsg ,MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,nZERO);
            MessageBox(NULL,acErrorMsg,
            defPROJECT_NAME,MB_OK|MB_ICONERROR|MB_TOPMOST);

        }

    }
    CATCH_ALL(pomE)
    {
        if(pomE != NULL )
        {
            // Get the exception error message
            pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
            //Display the error
            //AfxMessageBox(acErrorMsg ,MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,nZERO);
            MessageBox(NULL,acErrorMsg,
                       defPROJECT_NAME,MB_OK|MB_ICONERROR|MB_TOPMOST);
        }
    }
    END_CATCH_ALL

    return bReturn;
}
BOOL CComputeCheckSum::setCheckSumViaCom(CString& omStrConfigFileName,
                                        UCHAR* pucCheckSum, CString& strError)
{
    CStdioFile omStdiofile;
    CFileException omException;
    DWORD dwSize                 = 0;
    DWORD dwRead                 = 0;
    BOOL bReturn                 = FALSE;
    BOOL bFileOpen               = FALSE;
    CString omStrStrErrorMessage = "";
    char  acErrorMsg[defSIZE_OF_ERROR_BUFFER];
    // Open the configration file template.
    TRY
    {
        bFileOpen = omStdiofile.Open(omStrConfigFileName,
        CFile::modeReadWrite| CFile::typeBinary,
        &omException);
        if(bFileOpen!=FALSE)
        {
            UCHAR* pucBuff   = NULL;
            UCHAR  ucCheckSum = 0;
            // Get the size of file
            dwSize = (DWORD)omStdiofile.GetLength();
            pucBuff = static_cast<UCHAR*> (new UCHAR[dwSize]);
            if(pucBuff!=NULL)
            {
                // Read the whole file and put the content to pucBuff;
                dwRead = omStdiofile.Read(pucBuff,dwSize);
                // compute the checksum
                bReturn = computeCheckSum(pucBuff,dwSize, &ucCheckSum);
                if(bReturn == TRUE)
                {
                    // Seek to the last byte to store checksum
                    omStdiofile.Seek(dwSize,CFile::begin);
                    // Write one byte checksum
                    omStdiofile.Write(&ucCheckSum,1);
                    // return the checksum
                    if(pucCheckSum!= NULL )
                    {
                        *pucCheckSum = ucCheckSum;
                    }
                    else
                    {
                        bReturn = FALSE;
                    }
                }
                delete [] pucBuff;
                pucBuff = NULL;
            }
            omStdiofile.Close();
        }
        else
        {
            // Get the exception error message
            omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
            // configuration file open error notification
        }

    }
    CATCH_ALL(pomE)
    {
        if(pomE != NULL )
        {
            // Get the exception error message
            pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
        }
    }
    END_CATCH_ALL

    strError = acErrorMsg;

    return bReturn;
}