void
GaduAddContactPage::slotUinChanged( const QString & )
{
    emit dataValid( this, validateData() );
}
bool OAuthFunctions::authenticate(QString* out)
{
    // Check required data is valid.
    if ( !dataValid() )
    {
        if ( out )
        {
            *out = QString("Username or password not provided.");
        }

        return false;
    }

    // Set the username and password.
    std::string temp = toString(username());
    m_tc.setTwitterUsername(temp);
    temp = toString(password());
    m_tc.setTwitterPassword(temp);

    //qDebug() << "Username for authentication:" << m_szUsername << "Password:"******"Consumer key details not found.");
        }

        return false;
    }

    m_tc.getOAuth().setConsumerKey(toString(consumerKey()));
    SimpleCrypt& crypt = standardCrypt();
    m_tc.getOAuth().setConsumerSecret(toString(crypt.decryptToString(consumerSecret())));

    //qDebug() << "Consumer key:" << m_szConsumerKey << "Consumer secret:" << crypt.decryptToString(m_szConsumerSecret);

    // If we already have auth variables, just set them as needed.
    if ( FileManagement::readKVFile(AUTH_DETAILS_FILE, m_Auth) && !m_Auth.isEmpty() )
    {
        m_tc.getOAuth().setOAuthTokenKey(toString(authKey()));
        m_tc.getOAuth().setOAuthTokenSecret(toString(crypt.decryptToString(authSecret())));
        //qDebug() << "Auth key:" << m_szAuthKey << "Auth secret:" << m_szAuthSecret;

        // Verify we authenticated properly.
        if ( !m_tc.accountVerifyCredGet() )
        {
            if ( out )
            {
                std::string er;
                m_tc.getLastCurlError(er);
                *out = QString::fromStdString(er);
                //qDebug() << "Authentication error:" << *out;
            }

            return false;
        }

        if ( out )
        {
            std::string response;
            m_tc.getLastWebResponse(response);
            *out = QString::fromStdString(response);
            //qDebug() << "Authentication response:" << *out;
        }

        return true;
    }

    // Otherwise, get the variables.
    std::string url;
    m_tc.oAuthRequestToken(url);

    // If the PIN is handled automatically, do this now.
    if ( m_bHandlePin )
    {
        m_tc.oAuthHandlePIN(url);
    }
    else
    {
        // Construct a modal window that will return the PIN.
        QString pin = askUserForPin(QString::fromStdString(url));
        m_tc.getOAuth().setOAuthPin(toString(pin));
        //qDebug("PIN returned from user: %s", pin.toLatin1().constData());
    }

    // Exchange request token with access token.
    m_tc.oAuthAccessToken();

    // Save key and secret for later use.
    m_Auth.setKey(AUTH_ROOT);
    temp.clear();
    m_tc.getOAuth().getOAuthTokenKey(temp);
    setAuthKey(QString::fromStdString(temp));
    m_tc.getOAuth().getOAuthTokenSecret(temp);
    setAuthSecret(crypt.encryptToString(QString::fromStdString(temp)));
    //qDebug() << "Auth key:" << m_szAuthKey << "Auth secret:" << QString::fromStdString(temp);
    //qDebug() << "Encrypted auth key:" << m_szAuthSecret;
    FileManagement::writeKVFile(AUTH_DETAILS_FILE, m_Auth);

    // End OAuth!

    // Verify we authenticated properly.
    if ( !m_tc.accountVerifyCredGet() )
    {
        if ( out )
        {
            std::string er;
            m_tc.getLastCurlError(er);
            *out = QString::fromStdString(er);
            //qDebug() << "Authentication error:" << *out;
        }

        return false;
    }

    if ( out )
    {
        std::string response;
        m_tc.getLastWebResponse(response);
        *out = QString::fromStdString(response);
        //qDebug() << "Authentication response:" << *out;
    }

    return true;
}
Beispiel #3
0
void simulator(int C, int K, int L){

    int setSize = calculateSetSize(C, K, L);
    int lineSize = calculateLineSize(C, K, L);
    //First set of arrays for data
    int LRUArray[lineSize*setSize], tagArray[lineSize*setSize], validBitArray[lineSize*setSize];
    //First set of arrays for data
    int dataLRUArray[lineSize*setSize], dataTagArray[lineSize*setSize], dataValidBitArray[lineSize*setSize];
    //Second set of arrays for instruction
    int instructionLRUArray[lineSize*setSize], instructionTagArray[lineSize*setSize], instructionValidBitArray[lineSize*setSize];
    //Initializes all array entries to 0
    int i,j;
    //Initializing every LRU of the cache to a value between 0 - (lineSize-1)
    for(i = 0; i<lineSize; i++ ){
        for(j = 0; j<setSize; j++){
            LRUArray[i+j*lineSize] = i;
            validBitArray[i+j*lineSize] = 0;
            tagArray[i+j*lineSize] = 0;
            dataLRUArray[i+j*lineSize] = i;
            dataValidBitArray[i+j*lineSize] = 0;
            dataTagArray[i+j*lineSize] = 0;
            instructionLRUArray[i+j*lineSize] = i;
            instructionValidBitArray[i+j*lineSize] = 0;
            instructionTagArray[i+j*lineSize] = 0;
        }

    }

    int instruction, address, tag, set, setLine;
    double missNumber, totalMemoryReferences, dataMiss, instructionMiss, dataReferences, instructionReferences; //miss will take care of maintaining track of how many misses the simulator has, toatlIteratiosn just counts how many total addresses the simulator has.
    missNumber = 0;
    dataMiss = 0;
    instructionMiss = 0;
    dataReferences = 0;
    instructionReferences = 0;
    totalMemoryReferences = 0;
    instruction = 1;
    address = 0;
    FILE *ifp;   //Pointer to a file is declared
    ifp = fopen("trace.txt", "r"); // ifp points to file
                                  // trace.txt, opened for
                                  // reading
    while (!feof(ifp)) {  // exit if end-of-file reached
    fscanf(ifp, "%d %x", &instruction, &address); // read next line
        switch (instruction){ // cases 0 -3 run the same thing
            case 0:
            case 1:
                tag = decodeTag(address, C, K, L, setSize);
                set = decodeSet(address, C, K, L, setSize);
                //Printing information
                //printf("Address: %x \n Tag: %d \n Set: %d \n\n", address, tag, set);
                if((setLine = tagHit(dataTagArray, set, tag, lineSize)) > -1){
                    if(dataValid(dataValidBitArray, set, setLine, lineSize)>0){
                        updateLRU(dataLRUArray, set, setLine, lineSize);
                    }else{
                        writeToAddress(dataTagArray, set, tag, setLine, lineSize);
                        validateData(dataValidBitArray, set, setLine, lineSize);
                        updateLRU(dataLRUArray, set, setLine, lineSize);
                        dataMiss++;
                        missNumber++;
                    }
                }else{
                    setLine = writeToCache(dataTagArray, dataLRUArray, set, tag, lineSize);
                    validateData(dataValidBitArray, set, setLine, lineSize);
                    updateLRU(dataLRUArray, set, setLine, lineSize);
                    dataMiss++;
                    missNumber++;
                }
                dataReferences++;
                totalMemoryReferences++;
                break;

            case 2:
                tag = decodeTag(address, C, K, L, setSize);
                set = decodeSet(address, C, K, L, setSize);
                //Printing information
                //printf("Address: %x \n Tag: %d \n Set: %d \n\n", address, tag, set);
                if((setLine = tagHit(instructionTagArray, set, tag, lineSize)) > -1){
                    if(dataValid(instructionValidBitArray, set, setLine, lineSize)>0){
                        updateLRU(instructionLRUArray, set, setLine, lineSize);
                    }else{
                        writeToAddress(instructionTagArray, set, tag, setLine, lineSize);
                        validateData(instructionValidBitArray, set, setLine, lineSize);
                        updateLRU(instructionLRUArray, set, setLine, lineSize);
                        instructionMiss++;
                        missNumber++;
                    }
                }else{
                    setLine = writeToCache(instructionTagArray, LRUArray, set, tag, lineSize);
                    validateData(instructionValidBitArray, set, setLine, lineSize);
                    updateLRU(instructionLRUArray, set, setLine, lineSize);
                    instructionMiss++;
                    missNumber++;
                }
                instructionReferences++;
                totalMemoryReferences++;

                break;
            //End iteration
        //address++;
            case 3:break;
            case 4:
                clearCache(dataValidBitArray, lineSize, setSize);
                clearCache(instructionValidBitArray, lineSize, setSize);
                break;
        }
    }
    fclose(ifp); //  Close file
    double missRate = missNumber/totalMemoryReferences*100;
    //printCache(tagArray, validBitArray, LRUArray, setSize, lineSize);
    printf("%.0f misses, ", missNumber);
    printf("%.0f total memory references, ", totalMemoryReferences);
    printf("%2.4f  miss rate, \n\n", missRate);
}
Beispiel #4
0
void simulator(int C, int K, int L){

    int setSize = calculateSetSize(C, K, L);
    int lineSize = calculateLineSize(C, K, L);
    int LRUArray[lineSize*setSize], tagArray[lineSize*setSize], validBitArray[lineSize*setSize];
    //Initializes all array entries to 0
    int i,j;
    //Initializing every LRU of the cache to a value between 0 - (lineSize-1)
    for(i = 0; i<lineSize; i++ ){
        for(j = 0; j<setSize; j++){
            LRUArray[i+j*lineSize] = i;
            validBitArray[i+j*lineSize] = 0;
            tagArray[i+j*lineSize] = 0;
        }

    }

    int iter, instruction, address, tag, set, setLine;
    double missNumber, totalMemoryReferences; //miss will take care of maintaining track of how many misses the simulator has, toatlIteratiosn just counts how many total addresses the simulator has.
    missNumber = 0;
    totalMemoryReferences = 0;
    instruction = 1;
    iter = 0;
    srand(4342);
    while(iter < 100000){

        address = rand();
        //printf("%d\n", address);
        switch (instruction){ // cases 0 -3 run the same thing
            case 0:
            case 1:
            case 2:
                tag = decodeTag(address, C, K, L, setSize);
                set = decodeSet(address, C, K, L, setSize);
                //Printing information
                //printf("Address: %x \n Tag: %d \n Set: %d \n\n", address, tag, set);
                if((setLine = tagHit(tagArray, set, tag, lineSize)) > -1){
                    if(dataValid(validBitArray, set, setLine, lineSize)>0){
                        updateLRU(LRUArray, set, setLine, lineSize);
                    }else{
                        writeToAddress(tagArray, set, tag, setLine, lineSize);
                        validateData(validBitArray, set, setLine, lineSize);
                        updateLRU(LRUArray, set, setLine, lineSize);
                        missNumber++;
                    }
                }else{
                    setLine = writeToCache(tagArray, LRUArray, set, tag, lineSize);
                    validateData(validBitArray, set, setLine, lineSize);
                    updateLRU(LRUArray, set, setLine, lineSize);
                    missNumber++;
                }
                break;

            case 3:break;
            case 4:
                clearCache(validBitArray, lineSize, setSize);
                break;
        }
        iter++;
        totalMemoryReferences++;
    }

    double missRate = missNumber/totalMemoryReferences*100;
    //printCache(tagArray, validBitArray, LRUArray, setSize, lineSize);
    printf("%.0f misses, ", missNumber);
    printf("%.0f total memory references, ", totalMemoryReferences);
    printf("%2.4f  miss rate, \n\n", missRate);
}