void Client::readData() { QString line; while (_socket->canReadLine()) { line = _socket->readLine(); if (!line.isEmpty()) { line.resize(line.length() - 1); QStringList stringList = line.split(' '); if (!stringList.isEmpty()) { if (stringList[0] == NS_PING) sendMessage(line); else if (line == NS_NO_SUCH_CMD) _lastCmd = NO_CMD; else if (_lastCmd == NB_ASK_AUTH) logCmd(line); else if (_lastCmd == NB_USR_LOG) logEndCmd(line); else if (stringList[0] == NS_SALUT) salutCmd(stringList); else if (stringList[0] == NS_CMD_USR) getUsrCmd(line, stringList[1]); else if (line == NS_LOGIN_FAIL) { _socket->abort(); emit error("User identification fail"); } emit readyMessage(line); } } } }
static int syncOVS(EVMod *mod) { HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data; resetCmd(mod); resetExtras(mod); char line[SFVS_MAX_LINELEN]; myDebug(1, "==== ovs-vsctl version ===="); char *version_cmd[] = { SFVS_OVS_CMD, "--version", NULL}; // don't abort if this fails: readVersion returns NO as an easy way // to only see the first line. (Line number should really be supplied to // callback from myExec) mdata->ovs10 = NO; // assume newer version mdata->usingAtVar = NO; myExec((void *)mod, version_cmd, readVersion, line, SFVS_MAX_LINELEN, NULL); // adapt if OVS is upgraded under our feet if(mdata->ovs10 == NO) mdata->useAtVar = YES; if(mdata->config.error || mdata->config.num_collectors == 0 || (mdata->config.sampling_n == 0 && mdata->config.polling_secs == 0)) { // no config or no targets or no sampling/polling - clear everything myDebug(1, "no config found: clearing all OVS sFlow config"); setStr(&mdata->sflowUUID, "[]"); setState(mod, SFVSSTATE_SYNC_DESTROY); } else { // got config - assume here that we're going to create a new // sflow object, but if we find one we'll adopt it setStr(&mdata->sflowUUID, SFVS_NEW_SFLOW_ID); setState(mod, SFVSSTATE_SYNC_SEARCH); } myDebug(1, "==== list sflow ===="); char *list_sflow_cmd[] = { SFVS_OVS_CMD, "list", "sflow", NULL }; if(myExec((void *)mod, list_sflow_cmd, sFlowList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; if(mdata->useAtVar) { // we can add the create at the end } else { // create new sFlow object if there were none found (i.e. if // the sflowUUID has not changed from the initial setting we // gave it. if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) { addCreateSFlow(mod); logCmd(mod); strArrayAdd(mdata->cmd, NULL); // for execve(2) if(myExec((void *)mod, strArray(mdata->cmd), submitCreate, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; resetCmd(mod); } } // make sure every bridge is using this sFlow entry myDebug(1, "==== list bridge ===="); char *list_bridge_cmd[] = { SFVS_OVS_CMD, "list", "bridge", NULL}; if(myExec((void *)mod, list_bridge_cmd, bridgeList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; // now it's safe to delete any extras that we found for(int ex = strArrayN(mdata->extras); --ex >= 0; ) { addDestroySFlow(mod, strArrayAt(mdata->extras, ex)); } if(mdata->useAtVar) { // create new sFlow object if there were none found (i.e. if // the sflowUUID has not changed from the initial setting we // gave it. if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) { addCreateSFlow(mod); } } // if we decided to make any changes, submit them now mdata->cmdFailed = NO; if(strArrayN(mdata->cmd) > 1) { logCmd(mod); strArrayAdd(mdata->cmd, NULL); // for execve(2) if(myExec((void *)mod, strArray(mdata->cmd), submitChanges, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; if(mdata->usingAtVar && mdata->cmdFailed == NO) { // remember that it worked at least once mdata->usedAtVarOK = YES; } } return mdata->cmdFailed ? NO : YES; }