Files
RedBear-OS/recipes/wip/qt/qtscxml/source/examples/scxml/ftpclient/ftpcontrolchannel.cpp
T
vasilito ff4ff35918 feat: track all source trees in git — full fork offline-first model
Red Bear OS is a full fork. All sources must be available from git clone
with zero network access. Removed gitignore rules that excluded fetched
source trees under recipes/*/source/, local/recipes/kde/*/source/,
local/recipes/qt/*/source/, and vendor source trees.

Build artifacts (target/, build/, source.tar, *.o, *.so) remain excluded.

127291 files added — kernel, relibc, base, bootloader, pkgar, all KDE/Qt
frameworks, mesa, wayland, DRM drivers, and every other recipe source.
2026-05-14 10:55:53 +01:00

63 lines
1.9 KiB
C++

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "ftpcontrolchannel.h"
#include <QtCore/qcoreapplication.h>
FtpControlChannel::FtpControlChannel(QObject *parent) : QObject(parent)
{
connect(&m_socket, &QIODevice::readyRead,
this, &FtpControlChannel::onReadyRead);
connect(&m_socket, &QAbstractSocket::disconnected,
this, &FtpControlChannel::closed);
connect(&m_socket, &QAbstractSocket::connected, this, [this]() {
emit opened(m_socket.localAddress(), m_socket.localPort());
});
connect(&m_socket, &QAbstractSocket::errorOccurred,
this, &FtpControlChannel::error);
}
void FtpControlChannel::connectToServer(const QString &server)
{
m_socket.connectToHost(server, 21);
}
void FtpControlChannel::command(const QByteArray &command,
const QByteArray &params)
{
QByteArray sendData = command;
if (!params.isEmpty())
sendData += " " + params;
m_socket.write(sendData + "\r\n");
}
void FtpControlChannel::onReadyRead()
{
m_buffer.append(m_socket.readAll());
int rn = -1;
while ((rn = m_buffer.indexOf("\r\n")) != -1) {
QByteArray received = m_buffer.mid(0, rn);
m_buffer = m_buffer.mid(rn + 2);
int space = received.indexOf(' ');
if (space != -1) {
int code = received.mid(0, space).toInt();
if (code == 0) {
qDebug() << "Info received: " << received.mid(space + 1);
emit info(received.mid(space + 1));
} else {
qDebug() << "Reply received: " << received.mid(space + 1);
emit reply(code, received.mid(space + 1));
}
} else {
emit invalidReply(received);
}
}
}
void FtpControlChannel::error(QAbstractSocket::SocketError error)
{
qWarning() << "Socket error:" << error;
QCoreApplication::exit();
}