Exemplo n.º 1
0
void HttpSocket::handleNewConnection()
{
    DBUG;
    while (hasPendingConnections()) {
        QTcpSocket *socket = nextPendingConnection();

        // prevent clients from sending too much data
        socket->setReadBufferSize(constMaxBuffer);

        static const QLatin1String constIpV6Prefix("::ffff:");

        QString peer=socket->peerAddress().toString();
        QString ifaceAddress=serverAddress().toString();
        const bool hostOk=peer==ifaceAddress || peer==mpdAddr || peer==(constIpV6Prefix+mpdAddr) ||
                          peer==QLatin1String("127.0.0.1") || peer==(constIpV6Prefix+QLatin1String("127.0.0.1"));

        DBUG << "peer:" << peer << "mpd:" << mpdAddr << "iface:" << ifaceAddress << "ok:" << hostOk;
        if (!hostOk) {
            sendErrorResponse(socket, 400);
            socket->close();
            DBUG << "Not from valid host";
            return;
        }

        connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
        connect(socket, SIGNAL(disconnected()), this, SLOT(discardClient()));
    }
}
Exemplo n.º 2
0
void HttpDaemon::incomingConnection(int socket)
{
    QTcpSocket* s = new QTcpSocket(this);
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(socket);
}
Exemplo n.º 3
0
ClientSocket::ClientSocket( int sock, InfoData *i, QObject *parent, const char *name ) :
    QSocket( parent, name ), info( i )
{
    connect( this, SIGNAL(readyRead()), SLOT(readClient()) );
    connect( this, SIGNAL(connectionClosed()), SLOT(connectionClosed()) );
    setSocket( sock );
}
Exemplo n.º 4
0
int processPOPClientRequest(int clientfd) {
	int loop = TRUE;
	char *buffer;

	sendPOPWelcomeGreeting(clientfd);
	while(loop) {
		readClient(clientfd, &buffer);

		//TEST FOR QUIT
		if (strncasecmp(buffer, "kill", strlen("kill")) == 0) {//EXIT WHILE LOOP
			cleanAll();
			free(buffer);
			return(-2);
		}
		else if (strncasecmp(buffer, POP_QUIT, strlen(POP_QUIT)) == 0) {//EXIT WHILE LOOP
			if (processPOPQuit(clientfd, buffer) == 0) {
				loop = FALSE;
				cleanAll();
				strcpy(buffer," Goodbye");
				writeClient(clientfd, getMessage(FALSE, (char**) &buffer), TRUE);
			}
		}
		else
			processPOPCommands(clientfd, buffer);
		free(buffer);
	}
	return(0);
}
Exemplo n.º 5
0
void MainWindow::newConnection()
{
    QTcpSocket* clientTcpSocket = tcpServer->nextPendingConnection();
    connect(clientTcpSocket, SIGNAL(disconnected()), clientTcpSocket, SLOT(deleteLater()));
    connect(clientTcpSocket, SIGNAL(readyRead()), this, SLOT(readClient()));
    sendToClient(clientTcpSocket, "Server Response: Connected!");
}
Exemplo n.º 6
0
MegaSocket::MegaSocket(QObject *parent) :
    QTcpSocket(parent)
{
    nextBlockSize = 0;
    connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
}
Exemplo n.º 7
0
void HttpServer::incomingConnection(int socket)
{
    qDebug() << "Client connected: " << socket;
    QTcpSocket * s = new QTcpSocket(this);
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(socket);
}
Exemplo n.º 8
0
ClientSocket::ClientSocket( QObject *parent, QTcpSocket * socket, unsigned int maximum_len) :
  QObject( parent),
  sock(socket),
  maxLen(maximum_len)
{
      connect( sock, SIGNAL(readyRead()), this, SLOT(readClient()) );
      connect( sock, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()) );
}
Exemplo n.º 9
0
ExtPlaneConnection::ExtPlaneConnection(QObject *parent) : QTcpSocket(parent), updateInterval(0.333) {
    connect(this, SIGNAL(connected()), this, SLOT(socketConnected()));
    connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
    connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(&reconnectTimer, SIGNAL(timeout()), this, SLOT(tryReconnect()));
    server_ok = false;
    enableSimulatedRefs = false;
}
Exemplo n.º 10
0
Client::Client(QTcpSocket* socket,Server* s) {
    qDebug()<<"new Client";
    server=s;
    client_address=socket->peerAddress();
    iq_port=-1;
    bandscope_port=-1;
    connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(discardClient()));
}
Exemplo n.º 11
0
void HttpSocket::handleNewConnection()
{
    DBUG;
    while (hasPendingConnections()) {
        QTcpSocket *s = nextPendingConnection();
        connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
        connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    }
}
Exemplo n.º 12
0
bool ClientSocket::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: readClient(); break;
    case 1: connectionClosed(); break;
    default:
	return QSocket::qt_invoke( _id, _o );
    }
    return TRUE;
}
Exemplo n.º 13
0
ClientSocket::ClientSocket( int sock, QObject *parent, const char *name ) :
  Q3Socket( parent, name )
{
      connect( this, SIGNAL(readyRead()), SLOT(readClient()) );
      connect( this, SIGNAL(connectionClosed()), SLOT(connectionClosed()) );
      connect(graspItGUI->getIVmgr(), SIGNAL( processWorldPlanner(int) ), this, SLOT( outputPlannerResults(int)));
      connect(graspItGUI->getIVmgr(), SIGNAL( runObjectRecognition() ), this, SLOT( runObjectRecognition() ));
      connect(graspItGUI->getIVmgr(), SIGNAL( sendString(const QString &) ), this, SLOT( sendString(const QString &) ));      
      setSocket( sock );
}
ClientSocket::ClientSocket(QObject *parent)
: QTcpSocket(parent)
{
	connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
	connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));

	nextBlockSize = 0;
	loadLoginFile();

}
Exemplo n.º 15
0
void IslInterface::sharedCtor(const QSslCertificate &cert, const QSslKey &privateKey)
{
	socket = new QSslSocket(this);
	socket->setLocalCertificate(cert);
	socket->setPrivateKey(privateKey);
	
	connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()), Qt::QueuedConnection);
	connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
	connect(this, SIGNAL(outputBufferChanged()), this, SLOT(flushOutputBuffer()), Qt::QueuedConnection);
}
Exemplo n.º 16
0
void GKSServer::connectSocket()
{
  if (s != NULL)
    s->disconnectFromHost();

  s = this->nextPendingConnection();

  connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
  connect(s, SIGNAL(disconnected()), this, SLOT(killSocket()));
}
Exemplo n.º 17
0
TSocket::TSocket(QObject *parent)
        : QTcpSocket(parent)
{
        MagicNumber = 0x194FF881;

        connect(this, SIGNAL( readyRead() ), this, SLOT( readClient() ) );
        connect(this, SIGNAL( disconnected() ), this, SLOT( deleteLater() ) );

        nextBlockSize = 0;
}
Exemplo n.º 18
0
void Server::acceptConnection()
{
    if(ui->pushButtonListen->text() == "No Listen")
    {
        qDebug() << "new connect";

        clientConnection = tcpServer->nextPendingConnection();
        connect(clientConnection, SIGNAL(readyRead()), this, SLOT(readClient()));
    }

}
Exemplo n.º 19
0
void LocalHTTPServer::incomingConnection(qintptr descriptor)
{
    auto client = new QTcpSocket(this);

    QObject::connect(client, &QTcpSocket::readyRead,
        [client, this] { readClient(client); });
    QObject::connect(client, &QTcpSocket::disconnected, 
                     client, &QObject::deleteLater);

    client->setSocketDescriptor(descriptor);
}
Exemplo n.º 20
0
void HttpServer :: incomingConnection(int socket)
{
  if (disabled) return;
  QTcpSocket *s = new QTcpSocket(this);
  connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
  connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
  s->setSocketDescriptor(socket);
  
  QtServiceBase::instance()->logMessage("New Connection");
  
}
Exemplo n.º 21
0
void SocketProxy::handleServerWrite(const boost::system::error_code& e,
                                    std::size_t bytesTransferred)
{
   if (!e)
   {
      readClient();
   }
   else
   {
      handleError(e, ERROR_LOCATION);
   }
}
int ClientSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTcpSocket::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: readClient(); break;
        default: ;
        }
        _id -= 1;
    }
    return _id;
}
Exemplo n.º 23
0
TcpClient::TcpClient(QObject *parent, QTcpSocket *socket, DataRefProvider *refProvider) :
        QObject(parent), _socket(socket), _refProvider(refProvider)
{
    INFO << "Client connected from " << socket->peerAddress().toString();
    connect(_socket, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(_socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
    connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));

    QByteArray block;
    QTextStream out(&block, QIODevice::WriteOnly);
    out << "EXTPLANE 1\n";
    out.flush();
    _socket->write(block);
}
Exemplo n.º 24
0
void Worker::newSocket(qintptr socket)
{
    //qDebug() << m_name << " is handling a new request; thread id" << thread()->currentThreadId();

    TcpSocket* s = new TcpSocket(this);
    s->m_id = static_cast<unsigned int>(rand());
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(socket);
    s->setTimeout(1000*60*2);
#ifndef NO_LOG
    sLog() << m_name << " receive a new request from ip:" << s->peerAddress().toString();
#endif
}
Exemplo n.º 25
0
HttpClientPrivate::HttpClientPrivate(qintptr sockfd, HttpServer *server, SkinManager* skinManager, QObject *parent) :
#else
HttpClientPrivate::HttpClientPrivate(int     sockfd, HttpServer *server, SkinManager* skinManager, QObject *parent) :
#endif
    QObject(parent),
    m_sockfd(sockfd),
    m_server(server),
    m_skinManager(skinManager)

{
    Q_ASSERT(this->thread() == QThread::currentThread());

    m_socket = new QTcpSocket(this);
    if (!m_socket->setSocketDescriptor(m_sockfd)) {
        emit error(m_socket->error());
        return;
    }

    connect(m_socket, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
}

void HttpClientPrivate::readClient()
{
    Q_ASSERT(this->thread() == QThread::currentThread());

    if (m_socket->canReadLine()) {
        QByteArray bytesRead = m_socket->readLine();
        QStringList tokens = QString(bytesRead).split(QRegExp("[ \r\n][ \r\n]*"));

        while(m_socket->canReadLine()) {
            bytesRead = m_socket->readLine();
            QList<QByteArray> lineTokens = bytesRead.split(':');
            if (lineTokens.size() == 2) {
                m_request.insert(lineTokens[0], lineTokens[1].trimmed().replace("\r\n",""));

            }
        }

        if (tokens[0] == "GET") {
            QString get = tokens[1];

            if(get.startsWith("/qml"))
                readQmlRequest(get);
            else
                readMediaRequest(get);
        }
    }
}
Exemplo n.º 26
0
int Connection::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTcpSocket::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: messageReceived((*reinterpret_cast< std::string(*)>(_a[1]))); break;
        case 1: readClient(); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
Exemplo n.º 27
0
void	ServerW::checkFds()
{
	int		i;

	i = 0;
	while (i < MAX_FD)
	{
		if (FD_ISSET(i, &_fdRead))
			if (_fdType[i] == FD_SERVER)
				readServer();
			else
				readClient(i);
		++i;
	}
}
Exemplo n.º 28
0
void HttpDaemon::incomingConnection(qintptr socket)
{
    if (disabled)
        return;

    // When a new client connects, the server constructs a QTcpSocket and all
    // communication with the client is done over this QTcpSocket. QTcpSocket
    // works asynchronously, this means that all the communication is done
    // in the two slots readClient() and discardClient().
    QTcpSocket* s = new QTcpSocket(this);
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(socket);

}
Exemplo n.º 29
0
bool MythRAOPConnection::Init(void)
{
    // connect up the request socket
    m_textStream = new NetStream(m_socket);
    m_textStream->setCodec("UTF-8");
    if (!connect(m_socket, SIGNAL(readyRead()), this, SLOT(readClient())))
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect client socket signal.");
        return false;
    }

    // create the data socket
    m_dataSocket = new ServerPool();
    if (!connect(m_dataSocket, SIGNAL(newDatagram(QByteArray, QHostAddress, quint16)),
                 this,         SLOT(udpDataReady(QByteArray, QHostAddress, quint16))))
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect data socket signal.");
        return false;
    }

    // try a few ports in case the first is in use
    m_dataPort = m_dataSocket->tryBindingPort(m_dataPort, RAOP_PORT_RANGE);
    if (m_dataPort < 0)
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to bind to a port for data.");
        return false;
    }

    LOG(VB_GENERAL, LOG_INFO, LOC +
        QString("Bound to port %1 for incoming data").arg(m_dataPort));

    // load the private key
    if (!LoadKey())
        return false;

    // use internal volume control
    m_allowVolumeControl = gCoreContext->GetNumSetting("MythControlsVolume", 1);

    // start the watchdog timer to auto delete the client after a period of inactivity
    m_watchdogTimer = new QTimer();
    connect(m_watchdogTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    m_watchdogTimer->start(10000);

    m_dequeueAudioTimer = new QTimer();
    connect(m_dequeueAudioTimer, SIGNAL(timeout()), this, SLOT(ProcessAudio()));

    return true;
}
Exemplo n.º 30
0
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, Servatrice_DatabaseInterface *_databaseInterface, QObject *parent)
    : Server_ProtocolHandler(_server, _databaseInterface, parent),
      servatrice(_server),
      sqlInterface(reinterpret_cast<Servatrice_DatabaseInterface *>(databaseInterface)),
      messageInProgress(false),
      handshakeStarted(false)
{
    socket = new QTcpSocket(this);
    socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
    connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));

    // Never call flushOutputQueue directly from outputQueueChanged. In case of a socket error,
    // it could lead to this object being destroyed while another function is still on the call stack. -> mutex deadlocks etc.
    connect(this, SIGNAL(outputQueueChanged()), this, SLOT(flushOutputQueue()), Qt::QueuedConnection);
}