kdelibs/kioslave/http/http.cpp

104 lines
2.7 KiB
C++
Raw Normal View History

/* This file is part of the KDE libraries
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
2014-11-13 01:04:59 +02:00
*/
#include "http.h"
#include "kdebug.h"
#include "kcomponentdata.h"
2014-11-13 01:04:59 +02:00
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
2014-11-13 01:04:59 +02:00
#include <sys/types.h>
#include <unistd.h>
2014-11-13 01:04:59 +02:00
extern "C" int Q_DECL_EXPORT kdemain( int argc, char **argv )
2014-11-13 01:04:59 +02:00
{
QCoreApplication app(argc, argv);
2014-11-13 01:04:59 +02:00
KComponentData componentData( "kio_http", "kdelibs4" );
( void ) KGlobal::locale();
kDebug(7103) << "Starting " << getpid();
2014-11-13 01:04:59 +02:00
if (argc != 4)
{
fprintf(stderr, "Usage: kio_http protocol domain-socket1 domain-socket2\n");
exit(-1);
}
HttpProtocol slave(argv[2], argv[3]);
2014-11-13 01:04:59 +02:00
slave.dispatchLoop();
kDebug(7103) << "Done";
return 0;
2014-11-13 01:04:59 +02:00
}
HttpProtocol::HttpProtocol( const QByteArray &pool, const QByteArray &app )
: SlaveBase( "http", pool, app )
2014-11-13 01:04:59 +02:00
{
}
HttpProtocol::~HttpProtocol()
2014-11-13 01:04:59 +02:00
{
kDebug(7103);
2014-11-13 01:04:59 +02:00
}
void HttpProtocol::setHost( const QString& host, quint16 port, const QString& user, const QString& pass )
2014-11-13 01:04:59 +02:00
{
Q_UNUSED(port);
Q_UNUSED(user);
Q_UNUSED(pass);
2014-11-13 01:04:59 +02:00
kDebug(7103) << host << port;
2014-11-13 01:04:59 +02:00
}
void HttpProtocol::stat( const KUrl &url )
2014-11-13 01:04:59 +02:00
{
kDebug(7103);
error(KIO::ERR_UNSUPPORTED_ACTION, url.prettyUrl());
2014-11-13 01:04:59 +02:00
}
void HttpProtocol::get( const KUrl& url )
2014-11-13 01:04:59 +02:00
{
kDebug(7103) << url.prettyUrl();
QNetworkAccessManager netmanager(this);
QNetworkReply* netreply = netmanager.get(QNetworkRequest(url));
while (!netreply->isFinished()) {
QCoreApplication::processEvents();
}
if (netreply->error() != QNetworkReply::NoError) {
kWarning(7103) << netreply->error();
error(KIO::ERR_COULD_NOT_CONNECT, url.prettyUrl());
return;
}
data(netreply->readAll());
finished();
2014-11-13 01:04:59 +02:00
}
void HttpProtocol::put( const KUrl& url, int permissions, KIO::JobFlags flags )
2014-11-13 01:04:59 +02:00
{
Q_UNUSED(permissions);
Q_UNUSED(flags);
2014-11-13 01:04:59 +02:00
kDebug(7103);
error(KIO::ERR_UNSUPPORTED_ACTION, url.prettyUrl());
2014-11-13 01:04:59 +02:00
}