int NNTPConnector::supplyCredentials(char const *username, char const *password) { m_username = std::string(username); m_password = std::string(password); // // Supply username and password // std::stringstream ss; ss << "AUTHINFO USER " << username << "\r\n"; m_commandQueue.push(ss.str()); popAndIssueCommand(); std::vector<int> codeChecks; codeChecks.push_back(281); codeChecks.push_back(381); codeChecks.push_back(502); codeChecks.push_back(501); std::string response = getResponseString(1, "\n"); int status = getStatus(response); //qDebug()<<"supply credentials status: "<<status; // // If returned code is 381 then we also need to supply password // (note should return 281 on proper credentials) // if(status == 381) { qDebug()<<"Yes 381"; ss.str(""); ss << "AUTHINFO PASS " << password << "\r\n"; m_commandQueue.push(ss.str()); popAndIssueCommand(); response = getResponseString(1, "\n"); status = getStatus(response); } if(status == 501) { // syntax error (not recognized) // // AUTHINFO command not recognized so we just assume // username and pass not required so force the authority // status = 281; } // status 0 is a hack for passwordless logins sometimes // not working correctly, at least when tested with virginmedia if(status == 281 || status == 0) { authorized = true; } qDebug()<<"supply credentials status: "<<status; return status; }
int NNTPConnector::setGroup(QString const &group) { std::stringstream ss; ss << "GROUP " << group.toStdString() <<"\r\n"; qDebug() << "Pushing command"; m_commandQueue.push(ss.str()); popAndIssueCommand(); qDebug() << "popped and issued"; std::vector<int> codeChecks; codeChecks.push_back(211); // success codeChecks.push_back(411); // no such group m_bytesAll = 0; qDebug() << "getting response"; std::string response = getResponseString(1, "\r\n"); qDebug() << "got response "<<response.c_str(); int status = getStatus(response); // // Parse out very latest article id of group // std::stringstream groupParse(response); std::string scrap; std::getline(groupParse, scrap, ' '); std::getline(groupParse, scrap, ' '); std::getline(groupParse, scrap, ' '); std::getline(groupParse, scrap, ' '); m_lastArticleId = scrap; return status; }
void NNTPConnector::doPost(QString const &postData, QString const &postGroup, QString const &postFrom, QString const &postSubject) { m_commandQueue.push("POST\r\n"); popAndIssueCommand(); m_bytesAll = 0; std::string response = getResponseString(1, "\n"); int status = getStatus(response); qDebug() << "first post status: "<<status; qDebug() << "postData: "<<postData; if(status == 340) { qDebug() << "Good to post now!"; std::stringstream composer; qDebug() << "postFrom: "<<postFrom; composer << "From: "<<postFrom.toStdString()<<"\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); composer << "Newsgroups: "<<postGroup.toStdString()<<"\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); composer << "Subject: "<<postSubject.toStdString()<<"\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); composer << "Organization: none\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); composer << "\r\n"<<postData.toStdString() <<"\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); composer<<".\r\n"; m_commandQueue.push(composer.str()); popAndIssueCommand(); composer.str(""); m_commandQueue.push(composer.str()); popAndIssueCommand(); std::string response = getResponseString(1, "\n"); status = getStatus(response); } }
int NNTPConnector::getStatReturn() { std::string response = getResponseString(1, "\n", false); std::stringstream ss; int status; ss << response.c_str(); ss >> status; if(status != 223) { return -1; } int id; ss >> id; return id; }
int NBRequest::writeLaneResponse(OutputDevice& od, NBEdge* from, int fromLane, int pos) const { std::vector<NBEdge::Connection> connected = from->getConnectionsFromLane(fromLane); for (std::vector<NBEdge::Connection>::iterator j = connected.begin(); j != connected.end(); j++) { od.openTag(SUMO_TAG_REQUEST); od.writeAttr(SUMO_ATTR_INDEX, pos++); od.writeAttr(SUMO_ATTR_RESPONSE, getResponseString(from, (*j).toEdge, fromLane, (*j).mayDefinitelyPass)); od.writeAttr(SUMO_ATTR_FOES, getFoesString(from, (*j).toEdge)); if (!OptionsCont::getOptions().getBool("no-internal-links")) { od.writeAttr(SUMO_ATTR_CONT, j->haveVia); } od.closeTag(); } return pos; }
const StringBuffer& HttpResponse::getHeader() { static const string CRNL = "\r\n"; header.clear(); header.reserve(500); header.appendText("HTTP/1.1 "); header.appendText(getResponseString(code)); header.appendText(CRNL + "Server: Palo" + CRNL + "Connection: Keep-Alive" + CRNL + "Content-Type: "); header.appendText(contentType); header.appendText(CRNL + "Content-Length: "); header.appendInteger((uint32_t)body.length()); header.appendText(CRNL); if (!tokenName.empty()) { header.appendText(tokenName); header.appendText(": "); header.appendInteger((uint32_t)tokenValue); header.appendText(CRNL); } if (!secondTokenName.empty()) { header.appendText(secondTokenName); header.appendText(": "); header.appendInteger((uint32_t)secondTokenValue); header.appendText(CRNL); } for (list<pair<string, string> >::const_iterator fit = fields.begin(); fit != fields.end(); ++fit) { header.appendText( fit->first ); header.appendText( ": " ); header.appendText( fit->second ); header.appendText( CRNL ); } if (Server::getCrossOrigin().size()) { header.appendText( "Access-Control-Allow-Origin:" ); header.appendText( Server::getCrossOrigin() ); header.appendText( CRNL ); } header.appendText(CRNL); return header; }
int NNTPConnector::nntpConnect(QString const &str, int const port, bool const ssl) { m_server = str; m_port = port; m_ssl = ssl; if(nntp.state() == QAbstractSocket::ConnectedState){ nntpClose(); } if(ssl) { // encrypted qDebug() << "encrypted"; nntp.connectToHostEncrypted(str, port); } else { // standard unencrypted qDebug() << "standard"; nntp.connectToHost(str, port); } if((!ssl) ? (nntp.waitForConnected()) : (nntp.waitForEncrypted())) { qDebug() << "Connected!"; connected = true; // // Return status: note, should be 200 on success for // a server with posting capability or 201 for a server // without a posting capability // std::vector<int> codeChecks; codeChecks.push_back(200); // service available, posting allowed codeChecks.push_back(201); // posting not allowed codeChecks.push_back(400); // temp unavailable codeChecks.push_back(502); // permanently unavilable m_bytesAll = 0; std::string response = getResponseString(1, "\n"); int status = getStatus(response); return status; } else { qDebug() << "Not connected!"; return -1; } }
char* osmsMessageRegisterDigitalItemInstanceResponseError::encode() { XMLDocument* pDoc = new XMLDocument(); if (pDoc == NULL) return NULL; if (!pDoc->decode(xmlTemplate(), getName())) { delete pDoc; return NULL; } pDoc->setInteger("MessageType", getMessageType()); pDoc->setInteger("ErrorCode", getErrorCode()); pDoc->setString("ResponseString", getResponseString()); char *result = pDoc->encode(); delete pDoc; return result; }
string ofxInFocusSerial::getFirmwareVersion() { commandRead("FVS"); return getResponseString(); }