void fillMap(const std::vector<std::string>& inVector, std::map<unsigned int,std::string>& result){ std::vector<std::string>::const_iterator it; std::vector<std::string>::const_iterator itBeg=inVector.begin(); std::vector<std::string>::const_iterator itEnd=inVector.end(); for(it=itBeg;it!=itEnd;++it){ //std::cout<<*it<<std::endl; std::string rundelimeterStr(it->begin(),it->end()-1); std::string stateStr(it->end()-1,it->end()); //std::cout<<"rundelimeterStr "<<rundelimeterStr<<std::endl; float rundelimeter=0.0; if(!lumi::from_string(rundelimeter,rundelimeterStr,std::dec)){ std::cout<<"failed to convert string to float"<<std::endl; } //std::cout<<"stateStr "<<stateStr<<std::endl; // //logic of rounding: //for states physics_declared T,F, use ceil function to round up then convert to unsigned int, because T,F will be set at the next LS boundary //for state paused P, use floor function to round down then convert to unsigned int, because we count the LS as paused as long as it contains pause (this logic could be changed) // if(stateStr=="P"){ result.insert(std::make_pair((unsigned int)std::floor(rundelimeter),stateStr));}else if(stateStr=="T"||stateStr=="F"){ result.insert(std::make_pair((unsigned int)std::ceil(rundelimeter),stateStr)); }else{ throw std::runtime_error("unknown LS state"); } } }
void ExplorerReplicaSetTreeItem::updateState(bool isUp, bool isPrimary) { _isUp = isUp; _isPrimary = isPrimary; QString stateStr("[Unknown]"); if (!_isUp) { stateStr = "[Not Reachable]"; } else { stateStr = _isPrimary ? "[Primary]" : "[Secondary]"; } setDisabled(_isUp ? false : true); setText(0, QString::fromStdString(_repMemberHostAndPort.toString()) + " " + stateStr); setIcon(0, _isPrimary ? GuiRegistry::instance().serverPrimaryIcon() : GuiRegistry::instance().serverSecondaryIcon()); }
bool QstProtocol::waitForConnected( int timeout ) { QTime t; t.start(); bool ok = false; QTime t2; t2.start(); while (t.elapsed() < timeout && !ok) { ok = QTcpSocket::waitForConnected(timeout); if (!ok) { wait(100); if (t2.elapsed() > 1000) { t2.start(); reconnect(); } } } if (ok) { if (debug_on) { qDebug() << QString("%1 QstProtocol::waitForConnected(%2, %3) ...") .arg(uniqueId()).arg(timeout).arg(stateStr()).toLatin1(); } t2.start(); while (t.elapsed() < timeout && !isConnected()) { wait(10); if (!isConnected() && t2.elapsed() > 500) { postMessage( QstMessage(QLatin1String("QTEST_NEW_CONNECTION")) ); t2.start(); } } ok = isConnected(); } if (debug_on) { qDebug() << QString("%1 QstProtocol::waitForConnected() ... %2 (%3 ms)").arg(uniqueId()).arg(ok ? "OK" : "FAILED" ).arg(t.elapsed()).toLatin1(); if (!ok) qDebug() << errorStr(); } return ok; }
/** * Check file info from header against what's actually installed. * @param ts transaction set * @param h header to verify * @param omitMask bits to disable verify checks * @param incAttr skip files without these attrs (eg %ghost) * @param skipAttr skip files with these attrs (eg %ghost) * @return 0 no problems, 1 problems found */ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, rpmfileAttrs incAttrs, rpmfileAttrs skipAttrs) { rpmVerifyAttrs verifyResult = 0; rpmVerifyAttrs verifyAll = 0; /* assume no problems */ rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_FLAGS_VERIFY); if (fi == NULL) return 1; rpmfiInit(fi, 0); while (rpmfiNext(fi) >= 0) { rpmfileAttrs fileAttrs = rpmfiFFlags(fi); char *buf = NULL, *attrFormat; const char *fstate = NULL; char ac; /* If filtering by inclusion, skip non-matching (eg --configfiles) */ if (incAttrs && !(incAttrs & fileAttrs)) continue; /* Skip on attributes (eg from --noghost) */ if (skipAttrs & fileAttrs) continue; verifyResult = rpmfiVerify(fi, omitMask); /* Filter out timestamp differences of shared files */ if (verifyResult & RPMVERIFY_MTIME) { rpmdbMatchIterator mi; mi = rpmtsInitIterator(ts, RPMDBI_BASENAMES, rpmfiFN(fi), 0); if (rpmdbGetIteratorCount(mi) > 1) verifyResult &= ~RPMVERIFY_MTIME; rpmdbFreeIterator(mi); } /* State is only meaningful for installed packages */ if (headerGetInstance(h)) fstate = stateStr(rpmfiFState(fi)); attrFormat = rpmFFlagsString(fileAttrs, ""); ac = rstreq(attrFormat, "") ? ' ' : attrFormat[0]; if (verifyResult & RPMVERIFY_LSTATFAIL) { if (!(fileAttrs & (RPMFILE_MISSINGOK|RPMFILE_GHOST)) || rpmIsVerbose()) { rasprintf(&buf, _("missing %c %s"), ac, rpmfiFN(fi)); if ((verifyResult & RPMVERIFY_LSTATFAIL) != 0 && errno != ENOENT) { char *app; rasprintf(&app, " (%s)", strerror(errno)); rstrcat(&buf, app); free(app); } } } else if (verifyResult || fstate || rpmIsVerbose()) { char *verifyFormat = rpmVerifyString(verifyResult, "."); rasprintf(&buf, "%s %c %s", verifyFormat, ac, rpmfiFN(fi)); free(verifyFormat); } free(attrFormat); if (buf) { if (fstate) buf = rstrscat(&buf, " (", fstate, ")", NULL); rpmlog(RPMLOG_NOTICE, "%s\n", buf); buf = _free(buf); } verifyAll |= verifyResult; } rpmfiFree(fi); return (verifyAll != 0) ? 1 : 0; }
bool KSshProcess::connect() { if(mVersion == UNKNOWN_VER) { // we don't know the ssh version yet, so find out version(); if(mVersion == -1) { return false; } } // We'll put a limit on the number of state transitions // to ensure we don't go out of control. int transitionLimit = 500; while(--transitionLimit) { kdDebug(KSSHPROC) << "KSshProcess::connect(): " << "Connect state " << stateStr(mConnectState) << endl; QString line; // a line from ssh QString msgBuf; // buffer for important messages from ssh // which are to be returned to the user switch(mConnectState) { // STATE_START: // Executes the ssh binary with the options provided. If no options // have been specified, sets error and returns false. Continue to // state 1 if execution is successful, otherwise set error and // return false. case STATE_START: // reset some key values to safe values mAcceptHostKey = false; mKeyFingerprint = QString::null; mKnownHostsFile = QString::null; if(mArgs.isEmpty()) { kdDebug(KSSHPROC) << "KSshProcess::connect(): ssh options " "need to be set first using setArgs()" << endl; mError = ERR_NO_OPTIONS; mErrorMsg = i18n("No options provided for ssh execution."); return false; } if(ssh.exec(mSshPath.latin1(), mArgs)) { kdDebug(KSSHPROC) << "KSshProcess::connect(): ssh exec failed" << endl; mError = ERR_CANNOT_LAUNCH; mErrorMsg = i18n("Failed to execute ssh process."); return false; } kdDebug(KSSHPROC) << "KSshPRocess::connect(): ssh pid = " << ssh.pid() << endl; // set flag to indicate what have started a ssh process mRunning = true; mConnectState = STATE_WAIT_PROMPT; break; // STATE_WAIT_PROMPT: // Get a line of input from the ssh process. Check the contents // of the line to determine the next state. Ignore the line // if we don't recognize its contents. If the line contains // the continue prompt, we have an error since we should never // get that line in this state. Set ERR_INVALID_STATE error // and return false. case STATE_WAIT_PROMPT: line = getLine(); if(line.isNull()) { kdDebug(KSSHPROC) << "KSshProcess::connect(): " "Got null line in STATE_WAIT_PROMPT." << endl; mError = ERR_INTERACT; mErrorMsg = i18n("Error encountered while talking to ssh."); mConnectState = STATE_FATAL; } else if(line.find(QString::fromLatin1(passwordPrompt[mVersion]), 0, false) != -1) { mConnectState = STATE_TRY_PASSWD; } else if(line.find(passphrasePrompt[mVersion]) != -1) { mConnectState = STATE_TRY_PASSPHRASE; } else if(line.find(authSuccessMsg[mVersion]) != -1) { return true; } else if(line.find(authFailedMsg[mVersion]) != -1 && line.find(tryAgainMsg[mVersion]) == -1) { mConnectState = STATE_AUTH_FAILED; } else if(line.find(hostKeyMissingMsg[mVersion]) != -1) { mConnectState = STATE_NEW_KEY_WAIT_CONTINUE; } else if(line.find(hostKeyChangedMsg[mVersion]) != -1) { mConnectState = STATE_DIFF_KEY_WAIT_CONTINUE; } else if(line.find(continuePrompt[mVersion]) != -1) { // mConnectState = STATE_SEND_CONTINUE; kdDebug(KSSHPROC) << "KSshProcess:connect(): " "Got continue prompt where we shouldn't (STATE_WAIT_PROMPT)" << endl; mError = ERR_INTERACT; mErrorMsg = i18n("Error encountered while talking to ssh."); } else if(line.find(connectionClosedMsg[mVersion]) != -1) { mConnectState = STATE_FATAL; mError = ERR_CLOSED_BY_REMOTE_HOST; mErrorMsg = i18n("Connection closed by remote host."); } else if(line.find(changeHostKeyOnDiskPrompt[mVersion]) != -1) { // always say yes to this. It always comes after commerical ssh // prints a "continue to connect prompt". We assume that if the // user choose to continue, then they also want to save the // host key to disk. ssh.writeLine("yes"); } else { // ignore line } break; // STATE_TRY_PASSWD: // If we have password send it to the ssh process, else // set error ERR_NEED_PASSWD and return false to the caller. // The caller then must then call KSshProcess::setPassword(QString) // before calling KSshProcess::connect() again. // // Almost exactly liek STATE_TRY_PASSPHRASE. Check there if you // make changes here. case STATE_TRY_PASSWD: // We have a password prompt waiting for us to supply // a password. Send that password to ssh. If the caller // did not supply a password like we asked, then ask // again. if(!mPassword.isEmpty()) { // ssh.WaitSlave(); ssh.writeLine(mPassword.latin1()); // Overwrite the password so it isn't in memory. mPassword.fill(QChar('X')); // Set the password to null so we will request another // password if this one fails. mPassword = QString::null; mConnectState = STATE_WAIT_PROMPT; } else { kdDebug(KSSHPROC) << "KSshProcess::connect() " "Need password from caller." << endl; // The caller needs to supply a password before // connecting can continue. mError = ERR_NEED_PASSWD; mErrorMsg = i18n("Please supply a password."); mConnectState = STATE_TRY_PASSWD; return false; } break; // STATE_TRY_KEY_PASSPHRASE: // If we have passphrase send it to the ssh process, else // set error ERR_NEED_PASSPHRASE and return false to the caller. // The caller then must then call KSshProcess::setPassword(QString) // before calling KSshProcess::connect() again. // // Almost exactly like STATE_TRY_PASSWD. The only difference is // the error we set if we don't have a passphrase. We duplicate // this code to keep in the spirit of the state machine. case STATE_TRY_PASSPHRASE: // We have a passphrase prompt waiting for us to supply // a passphrase. Send that passphrase to ssh. If the caller // did not supply a passphrase like we asked, then ask // again. if(!mPassword.isEmpty()) { // ssh.WaitSlave(); ssh.writeLine(mPassword.latin1()); // Overwrite the password so it isn't in memory. mPassword.fill(QChar('X')); // Set the password to null so we will request another // password if this one fails. mPassword = QString::null; mConnectState = STATE_WAIT_PROMPT; } else { kdDebug(KSSHPROC) << "KSshProcess::connect() " "Need passphrase from caller." << endl; // The caller needs to supply a passphrase before // connecting can continue. mError = ERR_NEED_PASSPHRASE; mErrorMsg = i18n( "Please supply the passphrase for " "your SSH private key."); mConnectState = STATE_TRY_PASSPHRASE; return false; } break; // STATE_AUTH_FAILED: // Authentication has failed. Tell the caller by setting the // ERR_AUTH_FAILED error and returning false. If // auth has failed then ssh should have exited, but // we will kill it to make sure. case STATE_AUTH_FAILED: mError = ERR_AUTH_FAILED; mErrorMsg = i18n("Authentication to %1 failed").arg(mHost); mConnectState = STATE_FATAL; break; // STATE_NEW_KEY_WAIT_CONTINUE: // Grab lines from ssh until we get a continue prompt or a auth // denied. We will get the later if StrictHostKeyChecking is set // to yes. Go to STATE_NEW_KEY_CONTINUE if we get a continue prompt. case STATE_NEW_KEY_WAIT_CONTINUE: line = getLine(); if(line.isNull()) { kdDebug(KSSHPROC) << "KSshProcess::connect(): " "Got null line in STATE_NEW_KEY_WAIT_CONTINUE." << endl; mError = ERR_INTERACT; mErrorMsg = i18n("Error encountered while talking to ssh."); mConnectState = STATE_FATAL; } else if((line.find(authFailedMsg[mVersion]) != -1 && line.find(tryAgainMsg[mVersion]) == -1) || line.find(hostKeyVerifyFailedMsg[mVersion]) != -1) { mError = ERR_AUTH_FAILED_NEW_KEY; mErrorMsg = i18n( "The identity of the remote host '%1' could not be verified " "because the host's key is not in the \"known hosts\" file.") .arg(mHost); if(mKnownHostsFile.isEmpty()) { mErrorMsg += i18n( " Manually, add the host's key to the \"known hosts\" " "file or contact your administrator."); } else { mErrorMsg += i18n( " Manually, add the host's key to %1 " "or contact your administrator.") .arg(mKnownHostsFile); } mConnectState = STATE_FATAL; } else if(line.find(continuePrompt[mVersion]) != -1) { mConnectState = STATE_NEW_KEY_CONTINUE; } else if(line.find(connectionClosedMsg[mVersion]) != -1) { mConnectState = STATE_FATAL; mError = ERR_CLOSED_BY_REMOTE_HOST; mErrorMsg = i18n("Connection closed by remote host."); } else if(line.find(keyFingerprintMsg[mVersion]) != -1) { mKeyFingerprint = keyFingerprintMsg[mVersion].cap(); kdDebug(KSSHPROC) << "Found key fingerprint: " << mKeyFingerprint << endl; mConnectState = STATE_NEW_KEY_WAIT_CONTINUE; } else { // ignore line } break; // STATE_NEW_KEY_CONTINUE: // We got a continue prompt for the new key message. Set the error // message to reflect this, return false and hope for caller response. case STATE_NEW_KEY_CONTINUE: mError = ERR_NEW_HOST_KEY; mErrorMsg = i18n( "The identity of the remote host '%1' could not be " "verified. The host's key fingerprint is:\n%2\nYou should " "verify the fingerprint with the host's administrator before " "connecting.\n\n" "Would you like to accept the host's key and connect anyway? ") .arg(mHost) .arg(mKeyFingerprint); mConnectState = STATE_SEND_CONTINUE; return false; // STATE_DIFF_KEY_WAIT_CONTINUE: // Grab lines from ssh until we get a continue prompt or a auth // denied. We will get the later if StrictHostKeyChecking is set // to yes. Go to STATE_DIFF_KEY_CONTINUE if we get a continue prompt. case STATE_DIFF_KEY_WAIT_CONTINUE: line = getLine(); if(line.isNull()) { kdDebug(KSSHPROC) << "KSshProcess::connect(): " "Got null line in STATE_DIFF_KEY_WAIT_CONTINUE." << endl; mError = ERR_INTERACT; mErrorMsg = i18n("Error encountered while talking to ssh."); mConnectState = STATE_FATAL; } else if((line.find(authFailedMsg[mVersion]) != -1 && line.find(tryAgainMsg[mVersion]) == -1) || line.find(hostKeyVerifyFailedMsg[mVersion]) != -1) { mError = ERR_AUTH_FAILED_DIFF_KEY; mErrorMsg = i18n( "WARNING: The identity of the remote host '%1' has changed!\n\n" "Someone could be eavesdropping on your connection, or the " "administrator may have just changed the host's key. " "Either way, you should verify the host's key fingerprint with the host's " "administrator. The key fingerprint is:\n%2\n" "Add the correct host key to \"%3\" to " "get rid of this message.") .arg(mHost) .arg(mKeyFingerprint) .arg(mKnownHostsFile); mConnectState = STATE_FATAL; } else if(line.find(continuePrompt[mVersion]) != -1) { mConnectState = STATE_DIFF_KEY_CONTINUE; } else if(line.find(keyFingerprintMsg[mVersion]) != -1) { mKeyFingerprint = keyFingerprintMsg[mVersion].cap(); kdDebug(KSSHPROC) << "Found key fingerprint: " << mKeyFingerprint << endl; mConnectState = STATE_DIFF_KEY_WAIT_CONTINUE; } else if(line.find(knownHostsFileMsg[mVersion]) != -1) { mKnownHostsFile = (knownHostsFileMsg[mVersion]).cap(1); kdDebug(KSSHPROC) << "Found known hosts file name: " << mKnownHostsFile << endl; mConnectState = STATE_DIFF_KEY_WAIT_CONTINUE; } else { // ignore line } break; // STATE_DIFF_KEY_CONTINUE: // We got a continue prompt for the different key message. // Set ERR_DIFF_HOST_KEY error // and return false to signal need to caller action. case STATE_DIFF_KEY_CONTINUE: mError = ERR_DIFF_HOST_KEY; mErrorMsg = i18n( "WARNING: The identity of the remote host '%1' has changed!\n\n" "Someone could be eavesdropping on your connection, or the " "administrator may have just changed the host's key. " "Either way, you should verify the host's key fingerprint with the host's " "administrator before connecting. The key fingerprint is:\n%2\n\n" "Would you like to accept the host's new key and connect anyway?") .arg(mHost) .arg(mKeyFingerprint); mConnectState = STATE_SEND_CONTINUE; return false; // STATE_SEND_CONTINUE: // We found a continue prompt. Send our answer. case STATE_SEND_CONTINUE: if(mAcceptHostKey) { kdDebug(KSSHPROC) << "KSshProcess::connect(): " "host key accepted" << endl; ssh.writeLine("yes"); mConnectState = STATE_WAIT_PROMPT; } else { kdDebug(KSSHPROC) << "KSshProcess::connect(): " "host key rejected" << endl; ssh.writeLine("no"); mError = ERR_HOST_KEY_REJECTED; mErrorMsg = i18n("Host key was rejected."); mConnectState = STATE_FATAL; } break; // STATE_FATAL: // Something bad happened that we cannot recover from. // Kill the ssh process and set flags to show we have // ended the connection and killed ssh. // // mError and mErrorMsg should be set by the immediately // previous state. case STATE_FATAL: kill(); mConnected = false; mRunning = false; mConnectState = STATE_START; // mError, mErroMsg set by last state return false; default: kdDebug(KSSHPROC) << "KSshProcess::connect(): " "Invalid state number - " << mConnectState << endl; mError = ERR_INVALID_STATE; mConnectState = STATE_FATAL; } } // we should never get here kdDebug(KSSHPROC) << "KSshProcess::connect(): " << "After switch(). We shouldn't be here." << endl; mError = ERR_INTERNAL; return false; }
// set Processor and Environment states from XML or JSON in binary. // state is in JSON format. XML can be read for backwards compatibility.. // void MLPluginProcessor::setPatchAndEnvStatesFromBinary (const void* data, int sizeInBytes) { // first try getting XML from binary- this will fail if blob is not in XML format XmlElementPtr xmlState(getXmlFromBinary (data, sizeInBytes)); if (xmlState) { bool setViewAttributes = true; setStateFromXML(*xmlState, setViewAttributes); } else { // TODO uncompress here std::string stateStr (static_cast<const char *>(data), sizeInBytes); // trim starting whitespace const char * pStart = stateStr.data(); const char * pTrimmedStart = pStart; while(isspace(*pTrimmedStart) && (pTrimmedStart - pStart < sizeInBytes)) { pTrimmedStart++; } // assume JSON bool OK = true; cJSON* root = cJSON_Parse(pTrimmedStart); if(root) { cJSON* patchState = cJSON_GetObjectItem(root, "patch"); if(patchState) { mpPatchState->setStateFromJSON(patchState); } else { OK = false; } cJSON* environmentState = cJSON_GetObjectItem(root, "environment"); if(environmentState) { mpEnvironmentState->setStateFromJSON(environmentState); } else { OK = false; } cJSON_Delete(root); } if(!OK) { // TODO notify user in release debug() << "MLPluginProcessor::setPatchAndEnvStatesFromBinary: couldn't load JSON!\n"; } } // push state for access by "Revert To saved" mpPatchState->clearStateStack(); mpPatchState->pushStateToStack(); }