bool RemoteHost::connectServer() { if (isConnected()) return true; QLOG_TRACE() << "Connecting to Server: " << name() << " at host " << hostAddress(); m_connection = new SecureConnection::Connection(hostAddress(), userName(), port()); bool connected(false); switch (authentication()) { case Server::None: connected = false; break; case Server::Agent: connected = m_connection->connect(SecureConnection::Agent); break; case Server::PublicKey: connected = getPassphraseFromUserAndConnect(SecureConnection::PublicKey); break; case Server::HostBased: connected = getPassphraseFromUserAndConnect(SecureConnection::HostBased); break; case Server::KeyboardInteractive: connected = m_connection->connect(SecureConnection::KeyboardInteractive); break; case Server::Vault: connected = getPasswordFromVaultAndConnect(); break; case Server::Prompt: connected = getPasswordFromUserAndConnect(); break; } if (!connected) { QString msg("Connection to server "); msg += name() + " falied"; QMsgBox::warning(0, "IQmol", msg); delete m_connection; m_connection = 0; } return connected; }
int main(int argc, char *argv[]) { hydrazine::ArgumentParser parser(argc, argv); int port; std::string host; bool verbose; parser.parse("-p", "--port", port, 2011, "Port to connect on"); parser.parse("-h", "--host", host, "127.0.0.1", "Remote host to connect to"); parser.parse("-v", "--verbose", verbose, false, "Verbose printing"); try { //using boost::asio::ip::tcp; boost::asio::io_service io_service; boost::system::error_code error; boost::asio::ip::tcp::endpoint hostAddress(boost::asio::ip::address::from_string(host), port); boost::asio::ip::tcp::socket socket(io_service); socket.connect(hostAddress); if (verbose) { std::cout << "Connecting to: " << host << ":" << port << std::endl; } pingpong(socket, verbose); } catch (std::exception &exp) { std::cerr << "TestOcelotServer - " << exp.what() << std::endl; } return 0; }
/*! \since 5.0 This functions normalizes the path and domain of the cookie if they were previously empty. The \a url parameter is used to determine the correct domain and path. */ void QNetworkCookie::normalize(const QUrl &url) { // don't do path checking. See QTBUG-5815 if (d->path.isEmpty()) { QString pathAndFileName = url.path(); QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(QLatin1Char('/'))+1); if (defaultPath.isEmpty()) defaultPath = QLatin1Char('/'); d->path = defaultPath; } if (d->domain.isEmpty()) { d->domain = url.host(); } else { QHostAddress hostAddress(d->domain); if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol && hostAddress.protocol() != QAbstractSocket::IPv6Protocol && !d->domain.startsWith(QLatin1Char('.'))) { // Ensure the domain starts with a dot if its field was not empty // in the HTTP header. There are some servers that forget the // leading dot and this is actually forbidden according to RFC 2109, // but all browsers accept it anyway so we do that as well. d->domain.prepend(QLatin1Char('.')); } } }
bool CDRNNode::ConnectToPeer( const CORE::CString& address , const UInt16 port ) {GUCEF_TRACE; COMCORE::CHostAddress hostAddress( address, port ); return ConnectToPeer( hostAddress ); }
QNetworkRequest TvDevice::createChannelInformationRequest() { QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/data?target=cur_channel"; QNetworkRequest request; request.setUrl(QUrl(urlString)); request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml")); request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0")); request.setRawHeader("Connection", "Close"); return request; }
void MsgStream::init(void) { socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); QHostAddress hostAddress(peerAddress); socket->connectToHost(hostAddress, port); }
QPair<QNetworkRequest, QByteArray> TvDevice::createPressButtonRequest(const TvDevice::RemoteKey &key) { QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/command"; QNetworkRequest request; request.setUrl(QUrl(urlString)); request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8")); request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh")); QByteArray data; data.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"command\"><name>HandleKeyInput</name><value>"); data.append(QString::number(key).toUtf8()); data.append("</value></api></envelope>"); return QPair<QNetworkRequest, QByteArray>(request, data); }
bool ServerConfigurationDialog::testSshConnection(ServerConfiguration const& configuration) { bool okay(false); try { QString hostAddress(configuration.value(ServerConfiguration::HostAddress)); QString userName(configuration.value(ServerConfiguration::UserName)); Network::Connection::AuthenticationT authentication(configuration.authentication()); int port(configuration.port()); Network::SshConnection ssh(hostAddress, port); ssh.open(); ssh.authenticate(authentication, userName); QLOG_TRACE() << "Authentication successful"; QEventLoop loop; Network::Reply* reply(ssh.execute("ls")); QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); okay = (reply->status() == Network::Reply::Finished); if (okay) { QLOG_DEBUG() << "----------------------------"; QLOG_DEBUG() << reply->message(); QLOG_DEBUG() << "----------------------------"; }else { QString msg("Connection failed:\n"); msg += reply->message(); QMsgBox::warning(this, "IQmol", msg); } delete reply; }catch (Network::AuthenticationCancelled& err) { // don't do anything }catch (Network::AuthenticationError& err) { QMsgBox::warning(0, "IQmol", "Invalid username or password"); }catch (Exception& err) { okay = false; QMsgBox::warning(0, "IQmol", err.what()); } return okay; }
bool RemoteHost::getPasswordFromUserAndConnect() { QString msg("Password for "); QString password; msg += userName() + "@" + hostAddress(); bool okPushed(true); bool connected(false); while (!connected) { password = QInputDialog::getText(0, "IQmol", msg, QLineEdit::Password, QString(), &okPushed); if (okPushed) { connected = m_connection->connect(SecureConnection::Password, password); if (!connected) QMsgBox::warning(0, "IQmol", "Invalid password"); }else { break; } } OverwriteString(password); return connected; }
bool ServerConfigurationDialog::testHttpConnection(ServerConfiguration const& configuration) { bool okay(false); try { QString hostAddress(configuration.value(ServerConfiguration::HostAddress)); int port(configuration.port()); Network::HttpConnection http(hostAddress, port); http.open(); Network::Reply* reply(http.get("index.html")); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); okay = reply->status() == Network::Reply::Finished; if (okay) { QLOG_DEBUG() << "----------------------------"; QLOG_DEBUG() << reply->message(); QLOG_DEBUG() << "----------------------------"; }else { QString msg("Connection failed:\n"); msg += reply->message(); QMsgBox::warning(this, "IQmol", msg); } delete reply; }catch (Network::AuthenticationError& err) { QMsgBox::warning(this, "IQmol", "Invalid username or password"); }catch (Exception& err) { QMsgBox::warning(this, "IQmol", err.what()); } return okay; }
int SipLSendCommand::execute(int argc, char* argv[]) { int commandStatus = CommandProcessor::COMMAND_FAILED; UtlString messageBuffer; char buffer[1025]; int bufferSize = 1024; int charsRead; printf("send command with %d arguments\n", argc); if(argc != 5) { UtlString usage; getUsage(argv[0], &usage); printf("%s", usage.data()); } else { UtlString protocol(argv[2]); protocol.toUpper(); UtlString hostAddress(argv[3]); int hostPort = atoi(argv[4]); FILE* sipMessageFile = fopen(argv[1], "r"); if(sipMessageFile && hostPort > 0 && !hostAddress.isNull() && (protocol.compareTo("TCP") == 0 || protocol.compareTo("UDP") == 0)) { //printf("opened file: \"%s\"\n", argv[1]); do { charsRead = fread(buffer, 1, bufferSize, sipMessageFile); if(charsRead > 0) { messageBuffer.append(buffer, charsRead); } } while(charsRead); fclose(sipMessageFile); OsSocket* writeSocket = NULL; if(protocol.compareTo("TCP") == 0) writeSocket = new OsConnectionSocket(hostPort ,hostAddress); else if(protocol.compareTo("UDP") == 0) writeSocket = new OsDatagramSocket(hostPort ,hostAddress); //printf("Read file contents:\n%s\n====END====\n", messageBuffer.data()); //SipMessage message(messageBuffer.data()); int bytesSent; if((bytesSent = writeSocket->write(messageBuffer.data(), messageBuffer.length())) > 0) { commandStatus = CommandProcessor::COMMAND_SUCCESS; } else { printf("Failed to send SIP message"); } printf("Send message with %d bytes\n", bytesSent); } else if(!sipMessageFile) { printf("send file: \"%s\" does not exist\n", argv[1]); commandStatus = CommandProcessor::COMMAND_FAILED; } else if(hostPort <= 0) { printf("Invalid destination port: %s\n", argv[4]); commandStatus = CommandProcessor::COMMAND_FAILED; } else if(hostAddress.isNull()) { printf("Invalid destination address: %s\n", argv[3]); commandStatus = CommandProcessor::COMMAND_FAILED; } else if(protocol.compareTo("TCP") && protocol.compareTo("UDP")) { printf("Invalid protocol: %s\n", argv[2]); commandStatus = CommandProcessor::COMMAND_FAILED; } } return(commandStatus); }
void MainController::onShouldStartServer(const QString &addressString, quint16 port) { QHostAddress hostAddress(addressString); if (!hostAddress.isNull()) { networkServer()->startServer(hostAddress, port); } }
// ----------------------------------------------------------------------------- // Cfota_engine_api::TryResumeDownload // TryResumeDownload test method function. // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt Cfota_engine_api::TryResumeDownloadL( CStifItemParser& aItem ) { RSyncMLSession syncSession; syncSession.OpenL(); CleanupClosePushL(syncSession); RSyncMLDevManProfile DMProfile; DMProfile.CreateL( syncSession ); CleanupClosePushL( DMProfile); DMProfile.SetDisplayNameL(_L("####´53")); DMProfile.SetServerIdL(_L8("ServerID53")); DMProfile.SetCreatorId(85); DMProfile.SetPasswordL(_L8("Password")); DMProfile.SetServerPasswordL(_L8("ServerPassword")); DMProfile.SetUserNameL(_L8("Username")); DMProfile.UpdateL(); RSyncMLConnection connection; connection.OpenL( DMProfile, KUidNSmlMediumTypeInternet.iUid ); CleanupClosePushL( connection ); TPtrC stringHostaddress; if( aItem.GetNextString ( stringHostaddress ) == KErrNone ) { HBufC16* newaddr = stringHostaddress.AllocL(); TBuf8<100> hostAddress((newaddr->Des()).Collapse()); connection.SetServerURIL( hostAddress ); delete newaddr; } TSmlProfileId ProfileId = DMProfile.Identifier(); CleanupStack::PopAndDestroy(); // connection CleanupStack::PopAndDestroy(); // DMProfile CleanupStack::PopAndDestroy(); // syncSession session.OpenL(); TInt PkgId = 1; TBuf8<10> PkgName; PkgName.Copy(_L8("zkg")); TBuf8<10> PkgVersion; PkgVersion.Copy(_L8("1.0")); TPtrC stringPkgUrl; if( aItem.GetNextString ( stringPkgUrl ) == KErrNone ) { HBufC16* newurl = stringHostaddress.AllocL(); TBuf8<100> PkgURL((newurl->Des()).Collapse()); delete newurl; TInt err = session.Download(PkgId,PkgURL,ProfileId,PkgName,PkgVersion); if(err) { iLog->Log(_L("CFMSInterruptAob::TryResumeDownloadL()- download error")); return err; } } User::After(5000000*6); session.Close(); RWsSession iWsSession; TInt err = iWsSession.Connect(); if(err) { iLog->Log(_L("CFMSInterruptAob::TryResumeDownloadL()- Window server session error")); return err; } TApaTask(CCoeEnv::Static()->WsSession()); TApaTaskList tasklist(iWsSession); TApaTask task=tasklist.FindApp(TUid::Uid(0x101F6DE5)); if(task.Exists()) { task.KillTask(); } iWsSession.Close(); User::After(5000000*3); session.OpenL(); session.TryResumeDownload(); User::After(5000000*3); return KErrNone; }
// ----------------------------------------------------------------------------- // Cfota_engine_api::DownloadL // DownloadL test method function. // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt Cfota_engine_api::DownloadL( CStifItemParser& aItem ) { RSyncMLSession syncSession; syncSession.OpenL(); CleanupClosePushL(syncSession); RSyncMLDevManProfile DMProfile; DMProfile.CreateL( syncSession ); CleanupClosePushL( DMProfile); DMProfile.SetDisplayNameL(_L("####´52")); DMProfile.SetServerIdL(_L8("ServerID52")); DMProfile.SetCreatorId(85); DMProfile.SetPasswordL(_L8("Password")); DMProfile.SetServerPasswordL(_L8("ServerPassword")); DMProfile.SetUserNameL(_L8("Username")); DMProfile.UpdateL(); RSyncMLConnection connection; connection.OpenL( DMProfile, KUidNSmlMediumTypeInternet.iUid ); CleanupClosePushL( connection ); TPtrC stringHostaddress; if( aItem.GetNextString ( stringHostaddress ) == KErrNone ) { HBufC16* newaddr = stringHostaddress.AllocL(); TBuf8<100> hostAddress((newaddr->Des()).Collapse()); connection.SetServerURIL( hostAddress ); delete newaddr; } TSmlProfileId ProfileId = DMProfile.Identifier(); CleanupStack::PopAndDestroy(); // connection CleanupStack::PopAndDestroy(); // DMProfile CleanupStack::PopAndDestroy(); // syncSession RFotaEngineSession session; session.OpenL(); TInt PkgId = 1; TPtrC stringPkgUrl; if( aItem.GetNextString ( stringPkgUrl ) == KErrNone ) { HBufC16* newurl = stringHostaddress.AllocL(); TBuf8<100> PkgURL((newurl->Des()).Collapse()); delete newurl; TBuf8<10> PkgName; PkgName.Copy(_L8("zkg")); TBuf8<10> PkgVersion; PkgVersion.Copy(_L8("1.0")); TInt err = session.Download(PkgId,PkgURL,ProfileId,PkgName,PkgVersion); session.Close(); if(KErrNone != err) { return err; } } return KErrNone; }
void KodiConnection::onDisconnected() { qCDebug(dcKodi) << "disconnected from" << hostAddress().toString() << port(); m_connected = false; emit connectionStatusChanged(); }
void KodiConnection::onConnected() { qCDebug(dcKodi) << "connected successfully to" << hostAddress().toString() << port(); m_connected = true; emit connectionStatusChanged(); }