void ProcessesList::produzirListaProcessos(){ this->listaProcessos.clear(); QDir *directory; QFile *arquivo; QString *S; QStringList files; std::string data; QDir aDir("/proc"); aDir.setFilter(QDir::Dirs); QStringList entries = aDir.entryList(); this->numThreads = 0; for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry) { S = new QString("/proc/" + QString(*entry)); if((S->compare("/proc/.") == 0) || (S->compare("/proc/..") == 0)){ continue; } directory = new QDir(*S); if(!directory->exists()){ continue; } else if(!((S->toStdString()[6] >= '0') && (S->toStdString()[6] <= '9'))){ continue; } directory->setFilter(QDir::Files); arquivo = new QFile(*S + "/status"); if((!arquivo)){ qDebug() << "ERRO 1! (" << *S << ")"; continue; } else if(!arquivo->open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << arquivo->errorString(); qDebug() << "ERRO 2! (" << *S << ")"; continue; } process P; QTextStream buffer(arquivo); QStringList fileContent = buffer.readAll().split("\n"); QString buf; P.nome = processName(fileContent.at(0)); P.status = processStatus(fileContent.at(1)); P.pid = processPid(fileContent.at(3)); P.ppid = processPPid(fileContent.at(4)); P.user = processUser(fileContent.at(6)); for (int var = 7; var < fileContent.size(); ++var) { buf = fileContent.at(var); if(buf.startsWith("Threads")){ break; } } P.threads = processThreadsNumber(buf); this->numThreads += P.threads; P.trocas_contexto = processTrocasContexto(fileContent.at(fileContent.size()-3),fileContent.at(fileContent.size()-2)); this->listaProcessos.push_back(P); arquivo->close(); } delete arquivo; delete directory; delete S; }
void CGameWorld::process() { TRY_EXCEPT_RECORD(processListener()); TRY_EXCEPT_RECORD(processLink()); TRY_EXCEPT_RECORD(processUser()); }
/** * Processes all the POP3 commands such as * USER, PASS, LIST, RETR, DELE, NOOP, RSET, STAT */ int processPOPCommands(int sockfd, char *msg) { char *clientMsg = NULL; clientMsg = (char *)malloc(sizeof(char *) * 1024); if (clientMsg == NULL) { perror("ERROR: Cannot allocate memory"); return(-1); } if (strncasecmp(msg, POP_SSL_STARTTLS, strlen(POP_SSL_STARTTLS)) == 0) { //EHLO if (setupSSLCommunication(sockfd)) { writeClient(sockfd, "OK Begin TLS negotiation now", TRUE); } } else if (strncasecmp(msg, POP_USER, strlen(POP_USER)) == 0) { //USER if (checkPOPStates(iPOP_USER)) { if (processUser(msg)== -1) { strcpy(clientMsg,"User name required"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } else writeClient(sockfd, POP_OK, TRUE); } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else if (strncasecmp(msg, POP_PASS, strlen(POP_PASS)) == 0) { //PASS if (checkPOPStates(iPOP_PASS)) { if (processPassword(msg) == -1) { strcpy(clientMsg,"Password required"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } else { struct userdata *user; if (fetch_user_data(username, password, &user)) { //VALID USER //GET MESSAGE LISTING FOR THE USER getListMessages(username); writeClient(sockfd, POP_OK, TRUE); free(user); } else { strcpy(clientMsg,"Invalid User"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else if (strncasecmp(msg, POP_LIST, strlen(POP_LIST)) == 0) { //LIST if (checkPOPStates(iPOP_LIST)) processList(sockfd, msg); else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else if (strncasecmp(msg, POP_RETR, strlen(POP_RETR)) == 0) { //RETR if (checkPOPStates(iPOP_RETR)) { if (processRetr(sockfd, msg) == -1) { strcpy(clientMsg,"Invalid Syntax"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else if (strncasecmp(msg, POP_DELE, strlen(POP_DELE)) == 0) { //DELE if (checkPOPStates(iPOP_DELE)) { if (processDelete(sockfd, msg)== -1) { strcpy(clientMsg,"Invalid Syntax"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else if (strncasecmp(msg, POP_RSET, strlen(POP_RSET)) == 0) { //RSET // if (checkStates(iPOP_RSET)) // processRset(sockfd, msg); // else // writeClient(sockfd, POP_RESP_503, TRUE); } else if (strncasecmp(msg, POP_NOOP, strlen(POP_NOOP)) == 0) { //NOOP if (checkPOPStates(iPOP_NOOP)) writeClient(sockfd, POP_OK, TRUE); else writeClient(sockfd, POP_ERR, TRUE); } else if (strncasecmp(msg, POP_STAT, strlen(POP_STAT)) == 0) { //STAT if (checkPOPStates(iPOP_STAT)) { processStat(sockfd, msg); } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd, getMessage(TRUE, &clientMsg), TRUE); } } else { strcpy(clientMsg,"Invalid State"); writeClient(sockfd,getMessage(TRUE, &clientMsg), TRUE); } free(clientMsg); return(0); }