Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
0
void CHttpServer::incomingConnection(qintptr socket)
{
  if (isPaused())
    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);

  QtServiceBase::instance()->logMessage("New Connection");
}
Exemplo n.º 10
0
void QFrontDesk::incomingConnection(int socket) {
    //qDebug() << "incoming connection";
    r = rm->getFreeSlot();
    if(!r) {
        qDebug() << "no free slots";
        s = new QTcpSocket(this);
        s->setSocketDescriptor(socket);

        //todo
        QTextStream os(s);
        os << "HTTP/1.0 503 Service Unavailable\r\n Content-Type: text/html;"
              "charset=\"utf-8\"\r\n"
              "\r\n";
        os << "<!DOCTYPE html><html><body><h1>No free slots</h1><p>Try again later</p></body></html>";
        s->close();
        s->deleteLater();
        return;
    }
    r->setSocket(socket);
    connect(r->getSocket(), SIGNAL(readyRead()), r, SLOT(readClient()));
    connect(r->getSocket(), SIGNAL(disconnected()), r, SLOT(discardClient()));
    connect(r, SIGNAL(route(QString,Arguments*,QTcpSocket*)) , this, SLOT(resolveRoute(QString,Arguments*,QTcpSocket*)));
}
Exemplo n.º 11
0
//HTTP reception
void InterfaceHttpServer::incomingConnection(int socketDescriptor) {
    QTcpSocket *socket = new QTcpSocket(this);
    connect(socket, SIGNAL(readyRead()),    this, SLOT(readClient()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(discardClient()));
    socket->setSocketDescriptor(socketDescriptor);
}