# HG changeset patch # User Alexis Jeandet # Date 2015-06-08 16:33:57 # Node ID 8958118aec1a0cd40cb700c13ccb3cd423e9a521 # Parent b90d69939be9f10cb5f04eaa4abb354c09cce991 Working on restart option for data downloader. diff --git a/QLop.pro b/QLop.pro --- a/QLop.pro +++ b/QLop.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui network xml svg +QT += core gui network xml svg script CONFIG += pythonqt greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -22,10 +22,12 @@ LIBS+=-lfftw3_threads -lfftw3 INCLUDEPATH += src/QCustomPlot \ src src/Cassini \ + src/Core/network \ src/Core src/Core/Widgets \ src/Core/Widgets/PyWdgt defined(QLOP_DEBUG,var){ + message("building without optimisation") QMAKE_CXXFLAGS += -O0 -fopenmp QMAKE_LFLAGS += -O0 -fopenmp } @@ -41,8 +43,8 @@ SOURCES += src/main.cpp\ src/QCustomPlot/qcustomplot.cpp \ src/toolbarcontainer.cpp \ src/Core/abstractfileloader.cpp \ - src/Core/filedownloader.cpp \ - src/Core/filedownloadertask.cpp \ + src/Core/network/filedownloader.cpp \ + src/Core/network/filedownloadertask.cpp \ src/Core/Widgets/downloadhistory.cpp \ src/Core/Widgets/downloadhistoryelement.cpp \ src/Core/qlopservice.cpp \ @@ -70,15 +72,17 @@ SOURCES += src/main.cpp\ src/Core/qlopgui.cpp \ src/Core/Widgets/manualproxycfg_gui.cpp \ src/Core/Widgets/qlopsettingsdialog.cpp \ - src/Cassini/cassinitoolssettingsgui.cpp + src/Cassini/cassinitoolssettingsgui.cpp \ + src/Core/network/proxypacparser.cpp \ + src/Core/network/qlopnetworkproxyfactory.cpp HEADERS += src/mainwindow.h \ src/SocExplorerPlot.h \ src/QCustomPlot/qcustomplot.h \ src/toolbarcontainer.h \ src/Core/abstractfileloader.h \ - src/Core/filedownloader.h \ - src/Core/filedownloadertask.h \ + src/Core/network/filedownloader.h \ + src/Core/network/filedownloadertask.h \ src/Core/Widgets/downloadhistory.h \ src/Core/Widgets/downloadhistoryelement.h \ src/Core/qlopservice.h \ @@ -108,7 +112,9 @@ HEADERS += src/mainwindow.h \ src/Core/qlopgui.h \ src/Core/Widgets/manualproxycfg_gui.h \ src/Core/Widgets/qlopsettingsdialog.h \ - src/Cassini/cassinitoolssettingsgui.h + src/Cassini/cassinitoolssettingsgui.h \ + src/Core/network/proxypacparser.h \ + src/Core/network/qlopnetworkproxyfactory.h FORMS += src/mainwindow.ui \ src/Core/Widgets/downloadhistory.ui \ diff --git a/resources/qlop.qrc b/resources/qlop.qrc --- a/resources/qlop.qrc +++ b/resources/qlop.qrc @@ -8,6 +8,9 @@ QLop.svg Gnome-emblem-downloads.svg cassini.gif + restart.png + start.png + stop.png QLop.png diff --git a/resources/restart.png b/resources/restart.png new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..34146f47467033f4128e20df0222418bc99a38ae GIT binary patch literal 3205 zc$@)+40`j4P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcf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YR^X(K#(E3hQxTEoAFEz*fk%-`vCZ z1B+j5BV^5gC|N)+Wc}p<3rxU}c(;setupUi(this); diff --git a/src/Cassini/cassinitoolssettingsgui.h b/src/Cassini/cassinitoolssettingsgui.h --- a/src/Cassini/cassinitoolssettingsgui.h +++ b/src/Cassini/cassinitoolssettingsgui.h @@ -2,12 +2,12 @@ #define CASSINITOOLSSETTINGSGUI_H #include - +#include namespace Ui { class CassiniToolsSettingsGUI; } -class CassiniToolsSettingsGUI : public QWidget +class CassiniToolsSettingsGUI : public QLopSettingsItem { Q_OBJECT @@ -15,6 +15,8 @@ public: explicit CassiniToolsSettingsGUI(QWidget *parent = 0); ~CassiniToolsSettingsGUI(); +public slots: + void accept(){} protected: void changeEvent(QEvent *e); diff --git a/src/Core/Widgets/downloadhistoryelement.ui b/src/Core/Widgets/downloadhistoryelement.ui --- a/src/Core/Widgets/downloadhistoryelement.ui +++ b/src/Core/Widgets/downloadhistoryelement.ui @@ -51,8 +51,21 @@ + + + + + + + + :/img/stop.png:/img/stop.png + + + - + + + diff --git a/src/Core/Widgets/filedowloadersettingsgui.cpp b/src/Core/Widgets/filedowloadersettingsgui.cpp --- a/src/Core/Widgets/filedowloadersettingsgui.cpp +++ b/src/Core/Widgets/filedowloadersettingsgui.cpp @@ -21,15 +21,26 @@ ----------------------------------------------------------------------------*/ #include "filedowloadersettingsgui.h" #include "ui_filedowloadersettingsgui.h" +#include +#include +#include +#include FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) : - QWidget(parent), + QLopSettingsItem(parent), ui(new Ui::FileDowloaderSettingsGUI) { ui->setupUi(this); this->manualProxyCFG_GUI = new ManualProxyCFG_GUI(); lastWidget = NULL; connect(this->ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(proxyMethodChanged(QString))); + QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString(); + for(int i=0;icomboBox->count();i++) + { + if(!this->ui->comboBox->itemText(i).compare(proxyType)) + this->ui->comboBox->setCurrentIndex(i); + } + this->ui->defaultDestPath->setText(QLopSettings::value(FileDownloader::self(),"default_path",QDir::homePath()+"/Downloads").toString()); } FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI() @@ -49,10 +60,17 @@ void FileDowloaderSettingsGUI::changeEve } } +void FileDowloaderSettingsGUI::accept() +{ + QLopSettings::setValue(FileDownloader::self(),"default_path",this->ui->defaultDestPath->text()); + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,this->ui->comboBox->currentText()); + manualProxyCFG_GUI->saveConfig(); +} + void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text) { this->ui->gridLayout->removeWidget(this->lastWidget); - if(text=="manual") + if(text==CFG_PROXY_TYPE_VALUE_MANUAL) { this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1); this->lastWidget = this->manualProxyCFG_GUI; diff --git a/src/Core/Widgets/filedowloadersettingsgui.h b/src/Core/Widgets/filedowloadersettingsgui.h --- a/src/Core/Widgets/filedowloadersettingsgui.h +++ b/src/Core/Widgets/filedowloadersettingsgui.h @@ -24,22 +24,23 @@ #include #include "manualproxycfg_gui.h" +#include namespace Ui { class FileDowloaderSettingsGUI; } -class FileDowloaderSettingsGUI : public QWidget +class FileDowloaderSettingsGUI : public QLopSettingsItem { Q_OBJECT public: explicit FileDowloaderSettingsGUI(QWidget *parent = 0); ~FileDowloaderSettingsGUI(); - protected: void changeEvent(QEvent *e); - +public slots: + void accept(); private slots: void proxyMethodChanged(const QString & text); private: diff --git a/src/Core/Widgets/filedowloadersettingsgui.ui b/src/Core/Widgets/filedowloadersettingsgui.ui --- a/src/Core/Widgets/filedowloadersettingsgui.ui +++ b/src/Core/Widgets/filedowloadersettingsgui.ui @@ -22,7 +22,7 @@ - + diff --git a/src/Core/Widgets/manualproxycfg_gui.cpp b/src/Core/Widgets/manualproxycfg_gui.cpp --- a/src/Core/Widgets/manualproxycfg_gui.cpp +++ b/src/Core/Widgets/manualproxycfg_gui.cpp @@ -21,12 +21,15 @@ ----------------------------------------------------------------------------*/ #include "manualproxycfg_gui.h" #include "ui_manualproxycfg_gui.h" +#include +#include ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) : QWidget(parent), ui(new Ui::ManualProxyCFG_GUI) { ui->setupUi(this); + reloadConfig(); } ManualProxyCFG_GUI::~ManualProxyCFG_GUI() @@ -34,6 +37,41 @@ ManualProxyCFG_GUI::~ManualProxyCFG_GUI( delete ui; } +void ManualProxyCFG_GUI::reloadConfig() +{ + this->ui->httpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,"").toString()); + this->ui->httpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,"").toString()); + + this->ui->httpsHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,"").toString()); + this->ui->httpsPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,"").toString()); + + this->ui->ftpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,"").toString()); + this->ui->ftpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,"").toString()); + + this->ui->socksHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,"").toString()); + this->ui->socksPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,"").toString()); + + this->ui->IgnoreHosts->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,"localhost, 127.0.0.0/8, ::1").toString()); +} + +void ManualProxyCFG_GUI::saveConfig() +{ + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,this->ui->httpHost->text()); + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,this->ui->httpPort->text()); + + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,this->ui->httpsHost->text()); + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,this->ui->httpsPort->text()); + + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,this->ui->ftpHost->text()); + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,this->ui->ftpPort->text()); + + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,this->ui->socksHost->text()); + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,this->ui->socksPort->text()); + + QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,this->ui->IgnoreHosts->text()); + +} + void ManualProxyCFG_GUI::changeEvent(QEvent *e) { QWidget::changeEvent(e); diff --git a/src/Core/Widgets/manualproxycfg_gui.h b/src/Core/Widgets/manualproxycfg_gui.h --- a/src/Core/Widgets/manualproxycfg_gui.h +++ b/src/Core/Widgets/manualproxycfg_gui.h @@ -35,7 +35,8 @@ class ManualProxyCFG_GUI : public QWidge public: explicit ManualProxyCFG_GUI(QWidget *parent = 0); ~ManualProxyCFG_GUI(); - + void reloadConfig(); + void saveConfig(); protected: void changeEvent(QEvent *e); diff --git a/src/Core/Widgets/manualproxycfg_gui.ui b/src/Core/Widgets/manualproxycfg_gui.ui --- a/src/Core/Widgets/manualproxycfg_gui.ui +++ b/src/Core/Widgets/manualproxycfg_gui.ui @@ -16,46 +16,116 @@ + + + 0 + 0 + + HTTP proxy - + + + + 0 + 0 + + + + Put host address here + + + + + 0 + 0 + + HTTPS proxy - + + + + 0 + 0 + + + + Put host address here + + + + + 0 + 0 + + FTP proxy - + + + + 0 + 0 + + + + Put host address here + + + + + 0 + 0 + + SOCKS proxy - + + + + 0 + 0 + + + + Put host address here + + + + + 0 + 0 + + Ignore hosts @@ -64,7 +134,26 @@ - + + 0 + 0 + + + + 000000 + + + true + + + 0 to 65536 + + + + + + + 0 0 @@ -72,31 +161,51 @@ 000000 - - - - - - 000000 + + 0 to 65536 + + + 0 + 0 + + 000000 + + 0 to 65536 + + + + 0 + 0 + + 000000 + + 0 to 65536 + + + + 0 + 0 + + localhost, 127.0.0.0/8, ::1 diff --git a/src/Core/Widgets/qlopsettingsdialog.cpp b/src/Core/Widgets/qlopsettingsdialog.cpp --- a/src/Core/Widgets/qlopsettingsdialog.cpp +++ b/src/Core/Widgets/qlopsettingsdialog.cpp @@ -39,7 +39,7 @@ void QLopSettingsDialog::changePage(QLis ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current)); } -bool QLopSettingsDialog::registerConfigEntry(QWidget *configEntry, QIcon icon, QString text) +bool QLopSettingsDialog::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text) { if(configEntry!=NULL) { @@ -49,12 +49,13 @@ bool QLopSettingsDialog::registerConfigE configButton->setText(text); configButton->setTextAlignment(Qt::AlignHCenter); configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + connect(this,SIGNAL(accepted()),configEntry,SLOT(accept())); return true; } return false; } -void QLopSettingsDialog::popConfigDialog(QWidget *selectedConfigEntry) +void QLopSettingsDialog::popConfigDialog(QLopSettingsItem *selectedConfigEntry) { if(selectedConfigEntry!=NULL) { diff --git a/src/Core/Widgets/qlopsettingsdialog.h b/src/Core/Widgets/qlopsettingsdialog.h --- a/src/Core/Widgets/qlopsettingsdialog.h +++ b/src/Core/Widgets/qlopsettingsdialog.h @@ -8,6 +8,16 @@ class QLopSettingsDialog; } #include +class QLopSettingsItem : public QWidget +{ + Q_OBJECT +public: + QLopSettingsItem(QWidget *parent = 0):QWidget(parent) {} + ~QLopSettingsItem() {} +public slots: + virtual void accept()=0; +}; + class QLopSettingsDialog : public QDialog { Q_OBJECT @@ -18,8 +28,8 @@ public: public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); - bool registerConfigEntry(QWidget* configEntry, QIcon icon, QString text); - void popConfigDialog(QWidget* selectedConfigEntry=0); + bool registerConfigEntry(QLopSettingsItem* configEntry, QIcon icon, QString text); + void popConfigDialog(QLopSettingsItem* selectedConfigEntry=0); protected: void changeEvent(QEvent *e); diff --git a/src/Core/filedownloader.cpp b/src/Core/filedownloader.cpp deleted file mode 100644 --- a/src/Core/filedownloader.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the QLop Software --- Copyright (C) 2015, Plasma Physics Laboratory - CNRS --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------------*/ -/*-- Author : Alexis Jeandet --- Mail : alexis.jeandet@member.fsf.org -----------------------------------------------------------------------------*/ - -#include "filedownloader.h" -#include -#include - -FileDownloader* FileDownloader::_self=NULL; -QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; -QList* FileDownloader::m_pendingTasks=NULL; -QDockWidget* FileDownloader::m_gui=NULL; -DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; -FileDowloaderSettingsGUI* FileDownloader::m_SettingsGui=NULL; - -#define _INIT \ - if(Q_UNLIKELY(_self==NULL))\ - {\ - init();\ - }\ - - -int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) -{ - _INIT - if(QFile::exists(name)|| QFile::exists(name+".part")) - { - return -1; - } - FileDownloaderTask* task=NULL; - int ID=_self->getTaskId(); - if(ID!=-1) - { - QNetworkRequest request(fileUrl); - QNetworkReply* reply = m_WebCtrl->get(request); - if(reply && (reply->error()==QNetworkReply::NoError)) - { - task=new FileDownloaderTask(reply,ID,name,_self); - m_pendingTasks->append(task); - if(!_self->m_noGui) - { - m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); - } - } - else - { - return -1; - } - } - return ID; -} - -int FileDownloader::downloadFile(QString fileUrl, const QString &name) -{ - return downloadFile(QUrl(fileUrl),name); -} - -QDockWidget *FileDownloader::getGUI() -{ - if(!_self->m_noGui && (m_gui==NULL)) - { - m_DownLoadHistory=new DownLoadHistory(); - m_gui=new QDockWidget("Download History"); - m_gui->setWidget(m_DownLoadHistory); - m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); - m_SettingsGui = new FileDowloaderSettingsGUI(); - QLopSettings::registerConfigEntry(this->m_SettingsGui,QIcon(":/img/Gnome-emblem-downloads.svg"),"Qlop Downloader"); - } - return (QDockWidget*) m_gui; -} - -const QString &FileDownloader::serviceName() -{ - return m_serviceName; -} - -int FileDownloader::download_file(QUrl fileUrl, const QString &name) -{ - return downloadFile(fileUrl,name); -} - -int FileDownloader::download_file(QString fileUrl, const QString &name) -{ - return downloadFile(fileUrl,name); -} - -FileDownloaderTask* FileDownloader::getDownloadTask(int ID) -{ - _INIT - for(int i=0;icount();i++) - { - if(m_pendingTasks->at(i)->ID()==ID) - return m_pendingTasks->at(i); - } - return NULL; -} - -bool FileDownloader::taskIsCompleted(int ID) -{ - return getDownloadTask(ID)->downloadComplete(); -} - -FileDownloader *FileDownloader::self() -{ - _INIT - return _self; -} - -int FileDownloader::getTaskId() -{ - for(unsigned int i=0;icount();j++) - { - if(m_pendingTasks->at(j)->ID()==(int)i) - idValid=false; - } - if(idValid) - return (int)i; - } - return -1; -} - -void FileDownloader::proxyConfig() -{ - -} - -void FileDownloader::init(bool noGUI, QObject *parent) -{ - if(Q_UNLIKELY(_self==NULL)) - { - _self=new FileDownloader(noGUI,parent); - } -} -/*for gnome: - * - * gsettings list-recursively org.gnome.system.proxy - * gsettings get org.gnome.system.proxy.http host - * - * To detect desktop $XDG_CURRENT_DESKTOP - */ -FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) -{ - QNetworkProxyQuery q(QUrl(QLatin1String("http://www.google.com"))); - //q.setQueryType(QNetworkProxyQuery::UrlRequest); - //q.setProtocolTag("http"); - QList proxies = QNetworkProxyFactory::systemProxyForQuery(q); - foreach ( QNetworkProxy loopItem, proxies ) { - qDebug() << "proxyUsed:" << loopItem.hostName(); - } - if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) - QNetworkProxy::setApplicationProxy(proxies[0]); - else - qDebug("No proxy server selected"); - m_WebCtrl = new QNetworkAccessManager(this); - m_pendingTasks = new QList(); - m_noGui=noGUI; - m_serviceName="FileDownloader"; -} - -FileDownloader::~FileDownloader() -{ - if(!m_noGui) - delete m_gui; - while (m_pendingTasks->count()) - { - FileDownloaderTask* task=m_pendingTasks->last(); - m_pendingTasks->removeLast(); - delete task; - } - delete m_WebCtrl; -} - diff --git a/src/Core/filedownloader.h b/src/Core/filedownloader.h deleted file mode 100644 --- a/src/Core/filedownloader.h +++ /dev/null @@ -1,72 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the QLop Software --- Copyright (C) 2015, Plasma Physics Laboratory - CNRS --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------------*/ -/*-- Author : Alexis Jeandet --- Mail : alexis.jeandet@member.fsf.org -----------------------------------------------------------------------------*/ - -#ifndef FILEDOWNLOADER_H -#define FILEDOWNLOADER_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class FileDownloader : public QLopService -{ - Q_OBJECT -private: - static FileDownloader* _self; - static QNetworkAccessManager* m_WebCtrl; - static QList* m_pendingTasks; - static DownLoadHistory* m_DownLoadHistory; - static QDockWidget* m_gui; - static FileDowloaderSettingsGUI* m_SettingsGui; - FileDownloader(bool noGUI=false,QObject *parent = 0); - ~FileDownloader(); - -public: - static void init(bool noGUI=false,QObject *parent = 0); - static int downloadFile(QUrl fileUrl,const QString& name); - static int downloadFile(QString fileUrl,const QString& name); - static FileDownloaderTask *getDownloadTask(int ID); - static bool taskIsCompleted(int ID); - static FileDownloader *self(); - // QLopService methodes - QDockWidget* getGUI(); - const QString& serviceName(); -signals: - -public slots: - int download_file(QUrl fileUrl,const QString& name); - int download_file(QString fileUrl,const QString& name); -private: - int getTaskId(); - void proxyConfig(); -}; - -#endif // FILEDOWNLOADER_H diff --git a/src/Core/filedownloadertask.cpp b/src/Core/filedownloadertask.cpp deleted file mode 100644 --- a/src/Core/filedownloadertask.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the QLop Software --- Copyright (C) 2015, Plasma Physics Laboratory - CNRS --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------------*/ -/*-- Author : Alexis Jeandet --- Mail : alexis.jeandet@member.fsf.org -----------------------------------------------------------------------------*/ - -#include "filedownloadertask.h" - -FileDownloaderTask::FileDownloaderTask(QNetworkReply *reply, int ID, const QString &fileName, QObject *parent) : QObject(parent) -{ - this->m_Reply = reply; - this->m_downloadComplete = false; - this->m_FileName = fileName; - this->m_taskId = ID; - this->m_file = new QFile(fileName+".part"); - this->m_file->open(QIODevice::WriteOnly|QIODevice::Truncate); - this->m_startDateTime = QDateTime::currentDateTime(); - this->m_URL = m_Reply->url().toString(); - connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); - connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); - connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); - connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); -} - -FileDownloaderTask::~FileDownloaderTask() -{ - delete m_file; - delete m_Reply; -} - -int FileDownloaderTask::ID(){return m_taskId;} - -const QString &FileDownloaderTask::fileName(){return m_FileName;} - -const QString &FileDownloaderTask::url(){return m_URL;} - -const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} - -bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} - -void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) -{ - if(bytesTotal!=0) - emit updateProgress((100*bytesSent)/bytesTotal); -} - -void FileDownloaderTask::readReady() -{ - this->m_file->write(this->m_Reply->readAll()); -} - -void FileDownloaderTask::downloadFinished() -{ - this->m_downloadComplete = true; - this->m_file->write(this->m_Reply->readAll()); - this->m_file->close(); - this->m_file->rename(this->m_FileName); -} - diff --git a/src/Core/filedownloadertask.h b/src/Core/filedownloadertask.h deleted file mode 100644 --- a/src/Core/filedownloadertask.h +++ /dev/null @@ -1,67 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the QLop Software --- Copyright (C) 2015, Plasma Physics Laboratory - CNRS --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------------*/ -/*-- Author : Alexis Jeandet --- Mail : alexis.jeandet@member.fsf.org -----------------------------------------------------------------------------*/ - -#ifndef FILEDOWNLOADERTASK_H -#define FILEDOWNLOADERTASK_H - -#include -#include -#include -#include -#include -#include -#include - -// TODO add download speed and remaining time. - -class FileDownloaderTask : public QObject -{ - Q_OBJECT -public: - explicit FileDownloaderTask(QNetworkReply* reply,int ID,const QString& fileName,QObject *parent = 0); - ~FileDownloaderTask(); - int ID(); - const QString& fileName(); - const QString& url(); - const QDateTime& startDateTime(); - bool downloadComplete(); -signals: - void updateProgress(int percent); - void updateProgress(qint64 bytesSent, qint64 bytesTotal); -public slots: - -private slots: - void downloadProgress(qint64 bytesSent, qint64 bytesTotal); - void readReady(); - void downloadFinished(); -private: - int m_taskId; - QNetworkReply* m_Reply; - QByteArray m_DownloadedData; - bool m_downloadComplete; - QFile* m_file; - QString m_FileName; - QString m_URL; - QDateTime m_startDateTime; -}; - -#endif // FILEDOWNLOADERTASK_H diff --git a/src/Core/network/filedownloader.cpp b/src/Core/network/filedownloader.cpp new file mode 100644 --- /dev/null +++ b/src/Core/network/filedownloader.cpp @@ -0,0 +1,237 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ + +#include "filedownloader.h" +#include +#include +#include +#include + +FileDownloader* FileDownloader::_self=NULL; +QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; +QList* FileDownloader::m_pendingTasks=NULL; +QDockWidget* FileDownloader::m_gui=NULL; +DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; +FileDowloaderSettingsGUI* FileDownloader::m_SettingsGui=NULL; +QLopNetworkProxyFactory* FileDownloader::m_ProxyFactory=NULL; + +#define _INIT if(Q_UNLIKELY(_self==NULL)){ init();} + + + +int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) +{ + _INIT + if(QFile::exists(name)|| QFile::exists(name+".part")) + { + return -1; + } + int ID=_self->getTaskId(); + if(ID!=-1) + { + QNetworkRequest request(fileUrl); + QNetworkReply* reply = m_WebCtrl->head(request); + if(reply && (reply->error()==QNetworkReply::NoError)) + { + FileDownloaderTask*task=new FileDownloaderTask(reply,ID,name,_self); + m_pendingTasks->append(task); + connect(task, SIGNAL(gotHead(FileDownloaderTask*,QNetworkReply*)), _self, SLOT(gotHead(FileDownloaderTask*,QNetworkReply*))); + if(!_self->m_noGui) + { + m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); + } + } + else + { + return -1; + } + } + return ID; +} + +int FileDownloader::downloadFile(QString fileUrl, const QString &name) +{ + return downloadFile(QUrl(fileUrl),name); +} + +QDockWidget *FileDownloader::getGUI() +{ + if(!_self->m_noGui && (m_gui==NULL)) + { + m_DownLoadHistory=new DownLoadHistory(); + m_gui=new QDockWidget("Download History"); + m_gui->setWidget(m_DownLoadHistory); + m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); + m_SettingsGui = new FileDowloaderSettingsGUI(); + QLopSettings::registerConfigEntry(this->m_SettingsGui,QIcon(":/img/Gnome-emblem-downloads.svg"),"Qlop Downloader"); + } + return (QDockWidget*) m_gui; +} + +const QString &FileDownloader::serviceName() +{ + return m_serviceName; +} + +int FileDownloader::download_file(QUrl fileUrl, const QString &name) +{ + return downloadFile(fileUrl,name); +} + +int FileDownloader::download_file(QString fileUrl, const QString &name) +{ + return downloadFile(fileUrl,name); +} + +void FileDownloader::gotHead(FileDownloaderTask* task,QNetworkReply* headerreply) +{ + QNetworkReply* reply; + QByteArray rangeHeaderValue; + bool acceptRestart=false; + int DownloadTotalFileSize = headerreply->header(QNetworkRequest::ContentLengthHeader).toInt(); + if (headerreply->hasRawHeader("Accept-Ranges")) + { + QString qstrAcceptRanges = headerreply->rawHeader("Accept-Ranges"); + acceptRestart = (qstrAcceptRanges.compare("bytes", Qt::CaseInsensitive) == 0); + rangeHeaderValue = "bytes=" + QByteArray::number(task->startPosition()) + "-"; + if (DownloadTotalFileSize > 0) + { + rangeHeaderValue += QByteArray::number(DownloadTotalFileSize); + } + } + QNetworkRequest request(headerreply->request()); + delete headerreply; + request.setRawHeader("Connection", "Keep-Alive"); + if(acceptRestart) + request.setRawHeader("Range", rangeHeaderValue); + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + reply = m_WebCtrl->get(request); + task->restart(reply,acceptRestart); +} + +void FileDownloader::configureProxy() +{ + // QString proxyType = QLopSettings::value(FileDownloader::self(),"proxy/type","none").toString(); + // if(proxyType=="none") + // { + // QNetworkProxy proxy; + // proxy.setType(QNetworkProxy::Socks5Proxy); + // proxy.setHostName("proxy.example.com"); + // proxy.setPort(1080); + // proxy.setUser("username"); + // proxy.setPassword("password"); + // QNetworkProxy::setApplicationProxy(proxy); + // } + // QNetworkProxyQuery q(QUrl(QLatin1String("http://www.google.com"))); + // QList proxies = QNetworkProxyFactory::systemProxyForQuery(q); + // foreach ( QNetworkProxy loopItem, proxies ) { + // qDebug() << "proxyUsed:" << loopItem.hostName(); + // } + // if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) + // QNetworkProxy::setApplicationProxy(proxies[0]); + // else + // qDebug("No proxy server selected"); +} + +FileDownloaderTask* FileDownloader::getDownloadTask(int ID) +{ + _INIT + for(int i=0;icount();i++) + { + if(m_pendingTasks->at(i)->ID()==ID) + return m_pendingTasks->at(i); + } + return NULL; +} + +bool FileDownloader::taskIsCompleted(int ID) +{ + return getDownloadTask(ID)->downloadComplete(); +} + +FileDownloader *FileDownloader::self() +{ + _INIT + + return _self; + +} + +void FileDownloader::reloadConfig() +{ + m_ProxyFactory->reloadConfig(); +} + +int FileDownloader::getTaskId() +{ + for(unsigned int i=0;icount();j++) + { + if(m_pendingTasks->at(j)->ID()==(int)i) + idValid=false; + } + if(idValid) + return (int)i; + } + return -1; +} + +void FileDownloader::init(bool noGUI, QObject *parent) +{ + if(Q_UNLIKELY(_self==NULL)) + { + _self=new FileDownloader(noGUI,parent); + _self->reloadConfig(); + } +} +/*for gnome: + * + * gsettings list-recursively org.gnome.system.proxy + * gsettings get org.gnome.system.proxy.http host + * + * To detect desktop $XDG_CURRENT_DESKTOP + */ +FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) +{ + m_ProxyFactory = new QLopNetworkProxyFactory(); + // configureProxy(); + m_WebCtrl = new QNetworkAccessManager(this); + m_WebCtrl->setProxyFactory(m_ProxyFactory); + m_pendingTasks = new QList(); + m_noGui=noGUI; + m_serviceName="FileDownloader"; +} + +FileDownloader::~FileDownloader() +{ + if(!m_noGui) + delete m_gui; + while (m_pendingTasks->count()) + { + FileDownloaderTask* task=m_pendingTasks->last(); + m_pendingTasks->removeLast(); + delete task; + } + delete m_WebCtrl; +} diff --git a/src/Core/network/filedownloader.h b/src/Core/network/filedownloader.h new file mode 100644 --- /dev/null +++ b/src/Core/network/filedownloader.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ + +#ifndef FILEDOWNLOADER_H +#define FILEDOWNLOADER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class FileDownloader : public QLopService +{ + Q_OBJECT +private: + static FileDownloader* _self; + static QNetworkAccessManager* m_WebCtrl; + static QList* m_pendingTasks; + static DownLoadHistory* m_DownLoadHistory; + static QDockWidget* m_gui; + static QLopNetworkProxyFactory* m_ProxyFactory; + static FileDowloaderSettingsGUI* m_SettingsGui; + FileDownloader(bool noGUI=false,QObject *parent = 0); + ~FileDownloader(); + +public: + static void init(bool noGUI=false,QObject *parent = 0); + static int downloadFile(QUrl fileUrl,const QString& name); + static int downloadFile(QString fileUrl,const QString& name); + static FileDownloaderTask *getDownloadTask(int ID); + static bool taskIsCompleted(int ID); + static FileDownloader *self(); + void reloadConfig(); + // QLopService methodes + QDockWidget* getGUI(); + const QString& serviceName(); +signals: + +public slots: + int download_file(QUrl fileUrl,const QString& name); + int download_file(QString fileUrl,const QString& name); +private slots: + void gotHead(FileDownloaderTask *task, QNetworkReply *headerreply); +private: + void configureProxy(); + int getTaskId(); +}; + +#endif // FILEDOWNLOADER_H diff --git a/src/Core/network/filedownloadertask.cpp b/src/Core/network/filedownloadertask.cpp new file mode 100644 --- /dev/null +++ b/src/Core/network/filedownloadertask.cpp @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ + +#include "filedownloadertask.h" + +FileDownloaderTask::FileDownloaderTask(QNetworkReply *headerreply, int ID, const QString &fileName, QObject *parent) + : QObject(parent),p_acceptRestart(false) +{ + this->m_Reply = headerreply; + this->m_downloadComplete = false; + this->m_FileName = fileName; + this->m_taskId = ID; + this->m_file = new QFile(fileName+".part"); + this->m_file->open(QIODevice::WriteOnly|QIODevice::Append); + this->m_startPos = this->m_file->size(); + this->m_startDateTime = QDateTime::currentDateTime(); + this->m_URL = m_Reply->url().toString(); + connect(this->m_Reply,SIGNAL(finished()),this,SLOT(gotHead())); +} + +FileDownloaderTask::~FileDownloaderTask() +{ + delete m_file; + delete m_Reply; +} + +int FileDownloaderTask::ID(){return m_taskId;} + +const QString &FileDownloaderTask::fileName(){return m_FileName;} + +const QString &FileDownloaderTask::url(){return m_URL;} + +const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} + +bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} + +void FileDownloaderTask::restart(QNetworkReply *reply, bool acceptRestart) +{ + if(!acceptRestart) + this->m_file->seek(0); + this->p_acceptRestart = acceptRestart; + this->m_Reply = reply; + connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); + connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); + connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); + connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); +} + +int FileDownloaderTask::startPosition() +{ + return m_startPos; +} + +void FileDownloaderTask::gotHead() +{ + emit gotHead(this,m_Reply); +} + + +void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) +{ + if(bytesTotal!=0) + emit updateProgress((100*bytesSent)/bytesTotal); +} + +void FileDownloaderTask::readReady() +{ + this->m_file->write(this->m_Reply->readAll()); +} + +void FileDownloaderTask::downloadFinished() +{ + this->m_downloadComplete = true; + this->m_file->write(this->m_Reply->readAll()); + this->m_file->close(); + this->m_file->rename(this->m_FileName); +} + diff --git a/src/Core/network/filedownloadertask.h b/src/Core/network/filedownloadertask.h new file mode 100644 --- /dev/null +++ b/src/Core/network/filedownloadertask.h @@ -0,0 +1,73 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ + +#ifndef FILEDOWNLOADERTASK_H +#define FILEDOWNLOADERTASK_H + +#include +#include +#include +#include +#include +#include +#include + +// TODO add download speed and remaining time. + +class FileDownloaderTask : public QObject +{ + Q_OBJECT +public: + explicit FileDownloaderTask(QNetworkReply* headerreply, int ID, const QString& fileName, QObject *parent = 0); + ~FileDownloaderTask(); + int ID(); + const QString& fileName(); + const QString& url(); + const QDateTime& startDateTime(); + bool downloadComplete(); + void restart(QNetworkReply* reply,bool acceptRestart=false); + int startPosition(); +signals: + void updateProgress(int percent); + void updateProgress(qint64 bytesSent, qint64 bytesTotal); + void gotHead(FileDownloaderTask* task,QNetworkReply* headerreply); +public slots: + +private slots: + void gotHead(); + void downloadProgress(qint64 bytesSent, qint64 bytesTotal); + void readReady(); + void downloadFinished(); +private: + int m_taskId; + QNetworkReply* m_Reply; + QByteArray m_DownloadedData; + bool m_downloadComplete; + QFile* m_file; + QString m_FileName; + QString m_URL; + QDateTime m_startDateTime; + int m_startPos; + bool p_acceptRestart; +}; + +#endif // FILEDOWNLOADERTASK_H diff --git a/src/Core/network/proxypacparser.cpp b/src/Core/network/proxypacparser.cpp new file mode 100644 --- /dev/null +++ b/src/Core/network/proxypacparser.cpp @@ -0,0 +1,693 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +// based on Based on qt-examples: https://gitorious.org/qt-examples/qt-examples/blobs/master/pac-files +// and also KDE's KIO kpac source code: https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/show/src/kpac +// specially https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/entry/src/kpac/script.cpp + +#include "proxypacparser.h" +#include +#include +#include +#include + + +class Address +{ +public: + struct Error {}; + static Address resolve(const QString &host) + { + return Address(host); + } + + QList addresses() const + { + return m_addressList; + } + + QHostAddress address() const + { + if (m_addressList.isEmpty()) { + return QHostAddress(); + } + + return m_addressList.first(); + } + +private: + Address(const QString &host) + { + // Always try to see if it's already an IP first, to avoid Qt doing a + // needless reverse lookup + QHostAddress address(host); + if (address.isNull()) { + QHostInfo hostInfo; + if (hostInfo.hostName().isEmpty() || hostInfo.error() != QHostInfo::NoError) { + hostInfo = QHostInfo::fromName(host); + } + m_addressList = hostInfo.addresses(); + } else { + m_addressList.clear(); + m_addressList.append(address); + } + } + + QList m_addressList; +}; + +ProxyPacParser::ProxyPacParser(QObject *parent) +{ + engine = new QScriptEngine(this); + QScriptValue globalObject = engine->globalObject(); + + globalObject.setProperty(QString("isPlainHostName"), engine->newFunction(isPlainHostName)); + globalObject.setProperty(QString("dnsDomainIs"), engine->newFunction(dnsDomainIs)); + globalObject.setProperty(QString("localHostOrDomainIs"), engine->newFunction(localHostOrDomainIs)); + globalObject.setProperty(QString("isResolvable"), engine->newFunction(isResolvable)); + globalObject.setProperty(QString("isInNet"), engine->newFunction(isInNet)); + + //Related utility functions: + globalObject.setProperty(QString("dnsResolve"), engine->newFunction(dnsResolve)); + globalObject.setProperty(QString("myIpAddress"), engine->newFunction(myIpAddress)); + globalObject.setProperty(QString("dnsDomainLevels"), engine->newFunction(dnsDomainLevels)); + + //URL/hostname based conditions: + globalObject.setProperty(QString("shExpMatch"), engine->newFunction(shExpMatch)); + + // Time based conditions: + globalObject.setProperty(QString("weekdayRange"), engine->newFunction(weekdayRange)); + globalObject.setProperty(QString("dateRange"), engine->newFunction(dateRange)); + globalObject.setProperty(QString("timeRange"), engine->newFunction(timeRange)); + + //Implementation of Microsoft's IPv6 Extension for PAC + globalObject.setProperty(QString("isResolvableEx"), engine->newFunction(isResolvableEx)); + globalObject.setProperty(QString("isInNetEx"), engine->newFunction(isInNetEx)); + globalObject.setProperty(QString("dnsResolveEx"), engine->newFunction(dnsResolveEx)); + globalObject.setProperty(QString("myIpAddressEx"), engine->newFunction(myIpAddressEx)); + globalObject.setProperty(QString("sortIpAddressList"), engine->newFunction(sortIpAddressList)); + + +} + +ProxyPacParser::~ProxyPacParser() +{ + // delete engine; +} + +void ProxyPacParser::setPacFile(const QString &fileContent) +{ + engine->evaluate(fileContent); +} + +QString ProxyPacParser::findProxyForUrl(const QString &url, const QString &host) +{ + QScriptValue global = engine->globalObject(); + QScriptValue fun = global.property("FindProxyForURL"); + if ( !fun.isFunction() ) { + return QString("DIRECT"); + } + + QScriptValueList args; + args << engine->toScriptValue( url ) << engine->toScriptValue( host ); + + QScriptValue val = fun.call( global, args ); + + return val.toString(); +} + +template +static bool checkRange(T value, T min, T max) +{ + return ((min <= max && value >= min && value <= max) || + (min > max && (value <= min || value >= max))); +} + + +static bool isLocalHostAddress(const QHostAddress &address) +{ + if (address == QHostAddress::LocalHost) { + return true; + } + + if (address == QHostAddress::LocalHostIPv6) { + return true; + } + + return false; +} + +static bool isIPv6Address(const QHostAddress &address) +{ + return address.protocol() == QAbstractSocket::IPv6Protocol; +} + +static bool isIPv4Address(const QHostAddress &address) +{ + return (address.protocol() == QAbstractSocket::IPv4Protocol); +} + +static bool isSpecialAddress(const QHostAddress &address) +{ + // Catch all the special addresses and return false. + if (address == QHostAddress::Null) { + return true; + } + + if (address == QHostAddress::Any) { + return true; + } + + if (address == QHostAddress::AnyIPv6) { + return true; + } + + if (address == QHostAddress::Broadcast) { + return true; + } + + return false; +} + + +static bool addressLessThanComparison(const QHostAddress &addr1, const QHostAddress &addr2) +{ + if (addr1.protocol() == QAbstractSocket::IPv4Protocol && + addr2.protocol() == QAbstractSocket::IPv4Protocol) { + return addr1.toIPv4Address() < addr2.toIPv4Address(); + } + + if (addr1.protocol() == QAbstractSocket::IPv6Protocol && + addr2.protocol() == QAbstractSocket::IPv6Protocol) { + const Q_IPV6ADDR ipv6addr1 = addr1.toIPv6Address(); + const Q_IPV6ADDR ipv6addr2 = addr2.toIPv6Address(); + for (int i = 0; i < 16; ++i) { + if (ipv6addr1[i] != ipv6addr2[i]) { + return ((ipv6addr1[i] & 0xff) - (ipv6addr2[i] & 0xff)); + } + } + } + + return false; +} + +static QString addressListToString(const QList &addressList, + const QHash &actualEntryMap) +{ + QString result; + Q_FOREACH (const QHostAddress &address, addressList) { + if (!result.isEmpty()) { + result += QLatin1Char(';'); + } + result += actualEntryMap.value(address.toString()); + } + return result; +} + +const QDateTime ProxyPacParser::getTime(QScriptContext *context) +{ + const QString tz = context->argument(context->argumentCount() - 1).toString(); + if (tz.compare(QLatin1String("gmt"), Qt::CaseInsensitive) == 0) { + return QDateTime::currentDateTimeUtc(); + } + return QDateTime::currentDateTime(); +} + +int ProxyPacParser::findString(const QString &s, const char *const *values) +{ + int index = 0; + const QString lower = s.toLower(); + for (const char *const *p = values; *p; ++p, ++index) { + if (s.compare(QLatin1String(*p), Qt::CaseInsensitive) == 0) { + return index; + } + } + return -1; +} + +QScriptValue ProxyPacParser::myIpAddress(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() != 0 ) + return context->throwError("myIpAddress takes no arguments"); + + foreach( QHostAddress address, QNetworkInterface::allAddresses() ) { + if ( address != QHostAddress::LocalHost + && address != QHostAddress::LocalHostIPv6 ) + return QScriptValue( engine, address.toString() ); + } + + return engine->undefinedValue(); +} + +// dnsDomainLevels(host) +// @returns the number of dots ('.') in @p host +QScriptValue ProxyPacParser::dnsDomainLevels(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + const QString host = context->argument(0).toString(); + if (host.isNull()) { + return engine->toScriptValue(0); + } + return engine->toScriptValue(host.count(QLatin1Char('.'))); +} + +QScriptValue ProxyPacParser::isInNet(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() != 3 ) + return context->throwError("isInNet takes three arguments"); + + QHostAddress addr( context->argument(0).toString() ); + QHostAddress netaddr( context->argument(1).toString() ); + QHostAddress netmask( context->argument(2).toString() ); + + if ( (netaddr.toIPv4Address() & netmask.toIPv4Address()) == (addr.toIPv4Address() & netmask.toIPv4Address()) ) + return QScriptValue( engine, true ); + + return QScriptValue( engine, false ); +} + +QScriptValue ProxyPacParser::shExpMatch(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() != 2 ) + return context->throwError("shExpMatch takes two arguments"); + + QRegExp re( context->argument(1).toString(), Qt::CaseSensitive, QRegExp::Wildcard ); + if ( re.exactMatch( context->argument(0).toString() ) ) + return QScriptValue( engine, true ); + + return QScriptValue( engine, false ); +} + +// weekdayRange(day [, "GMT" ]) +// weekdayRange(day1, day2 [, "GMT" ]) +// @returns true if the current day equals day or between day1 and day2 resp. +// If the last argument is "GMT", GMT timezone is used, otherwise local time +QScriptValue ProxyPacParser::weekdayRange(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() < 1 || context->argumentCount() > 3) { + return engine->undefinedValue(); + } + + static const char *const days[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat", 0 }; + + const int d1 = findString(context->argument(0).toString(), days); + if (d1 == -1) { + return engine->undefinedValue(); + } + + int d2 = findString(context->argument(1).toString(), days); + if (d2 == -1) { + d2 = d1; + } + + // Adjust the days of week coming from QDateTime since it starts + // counting with Monday as 1 and ends with Sunday as day 7. + int dayOfWeek = getTime(context).date().dayOfWeek(); + if (dayOfWeek == 7) { + dayOfWeek = 0; + } + return engine->toScriptValue(checkRange(dayOfWeek, d1, d2)); +} + +// dateRange(day [, "GMT" ]) +// dateRange(day1, day2 [, "GMT" ]) +// dateRange(month [, "GMT" ]) +// dateRange(month1, month2 [, "GMT" ]) +// dateRange(year [, "GMT" ]) +// dateRange(year1, year2 [, "GMT" ]) +// dateRange(day1, month1, day2, month2 [, "GMT" ]) +// dateRange(month1, year1, month2, year2 [, "GMT" ]) +// dateRange(day1, month1, year1, day2, month2, year2 [, "GMT" ]) +// @returns true if the current date (GMT or local time according to +// presence of "GMT" as last argument) is within the given range +QScriptValue ProxyPacParser::dateRange(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() < 1 || context->argumentCount() > 7) { + return engine->undefinedValue(); + } + + static const char *const months[] = { "jan", "feb", "mar", "apr", "may", "jun", + "jul", "aug", "sep", "oct", "nov", "dec", 0 + }; + + QVector values; + for (int i = 0; i < context->argumentCount(); ++i) { + int value = -1; + if (context->argument(i).isNumber()) { + value = context->argument(i).toInt32(); + } else { + // QDate starts counting months from 1, so we add 1 here. + value = findString(context->argument(i).toString(), months) + 1; + } + + if (value > 0) { + values.append(value); + } else { + break; + } + } + + const QDate now = getTime(context).date(); + + // day1, month1, year1, day2, month2, year2 + if (values.size() == 6) { + const QDate d1(values[2], values[1], values[0]); + const QDate d2(values[5], values[4], values[3]); + return engine->toScriptValue(checkRange(now, d1, d2)); + } + // day1, month1, day2, month2 + else if (values.size() == 4 && values[ 1 ] < 13 && values[ 3 ] < 13) { + const QDate d1(now.year(), values[1], values[0]); + const QDate d2(now.year(), values[3], values[2]); + return engine->toScriptValue(checkRange(now, d1, d2)); + } + // month1, year1, month2, year2 + else if (values.size() == 4) { + const QDate d1(values[1], values[0], now.day()); + const QDate d2(values[3], values[2], now.day()); + return engine->toScriptValue(checkRange(now, d1, d2)); + } + // year1, year2 + else if (values.size() == 2 && values[0] >= 1000 && values[1] >= 1000) { + return engine->toScriptValue(checkRange(now.year(), values[0], values[1])); + } + // day1, day2 + else if (values.size() == 2 && context->argument(0).isNumber() && context->argument(1).isNumber()) { + return engine->toScriptValue(checkRange(now.day(), values[0], values[1])); + } + // month1, month2 + else if (values.size() == 2) { + return engine->toScriptValue(checkRange(now.month(), values[0], values[1])); + } + // year + else if (values.size() == 1 && values[ 0 ] >= 1000) { + return engine->toScriptValue(checkRange(now.year(), values[0], values[0])); + } + // day + else if (values.size() == 1 && context->argument(0).isNumber()) { + return engine->toScriptValue(checkRange(now.day(), values[0], values[0])); + } + // month + else if (values.size() == 1) { + return engine->toScriptValue(checkRange(now.month(), values[0], values[0])); + } + + return engine->undefinedValue(); +} + +// timeRange(hour [, "GMT" ]) +// timeRange(hour1, hour2 [, "GMT" ]) +// timeRange(hour1, min1, hour2, min2 [, "GMT" ]) +// timeRange(hour1, min1, sec1, hour2, min2, sec2 [, "GMT" ]) +// @returns true if the current time (GMT or local based on presence +// of "GMT" argument) is within the given range +QScriptValue ProxyPacParser::timeRange(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() < 1 || context->argumentCount() > 7) { + return engine->undefinedValue(); + } + + QVector values; + for (int i = 0; i < context->argumentCount(); ++i) { + if (!context->argument(i).isNumber()) { + break; + } + values.append(context->argument(i).toNumber()); + } + + const QTime now = getTime(context).time(); + + // hour1, min1, sec1, hour2, min2, sec2 + if (values.size() == 6) { + const QTime t1(values[0], values[1], values[2]); + const QTime t2(values[3], values[4], values[5]); + return engine->toScriptValue(checkRange(now, t1, t2)); + } + // hour1, min1, hour2, min2 + else if (values.size() == 4) { + const QTime t1(values[0], values[1]); + const QTime t2(values[2], values[3]); + return engine->toScriptValue(checkRange(now, t1, t2)); + } + // hour1, hour2 + else if (values.size() == 2) { + return engine->toScriptValue(checkRange(now.hour(), values[0], values[1])); + } + // hour + else if (values.size() == 1) { + return engine->toScriptValue(checkRange(now.hour(), values[0], values[0])); + } + + return engine->undefinedValue(); +} + +QScriptValue ProxyPacParser::dnsResolve(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() != 1 ) + return context->throwError("dnsResolve takes one arguments"); + + QHostInfo info = QHostInfo::fromName( context->argument(0).toString() ); + QList addresses = info.addresses(); + if ( addresses.isEmpty() ) + return engine->nullValue(); // TODO: Should this be undefined or an exception? check other implementations + + return QScriptValue( engine, addresses.first().toString() ); +} + +QScriptValue ProxyPacParser::dnsDomainIs(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() != 2 ) + return context->throwError("dnsDomainIs takes two arguments"); + + QHostInfo info = QHostInfo::fromName( context->argument(0).toString() ); + QString domain = info.localDomainName(); + QString argDomain = context->argument(1).toString(); + + if ( !domain.compare(argDomain) || !argDomain.compare("."+domain)) + return QScriptValue( engine, true ); + return QScriptValue( engine, false); +} + +// localHostOrDomainIs(host, fqdn) +// @returns true if @p host is unqualified or equals @p fqdn +QScriptValue ProxyPacParser::localHostOrDomainIs(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 2) { + return engine->undefinedValue(); + } + + const QString host = context->argument(0).toString(); + if (!host.contains(QLatin1Char('.'))) { + return engine->toScriptValue(true); + } + const QString fqdn = context->argument(1).toString(); + return engine->toScriptValue((host.compare(fqdn, Qt::CaseInsensitive) == 0)); +} + +// isResolvable(host) +// @returns true if host is resolvable to a IPv4 address. +QScriptValue ProxyPacParser::isResolvable(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + + try { + const Address info = Address::resolve(context->argument(0).toString()); + bool hasResolvableIPv4Address = false; + + Q_FOREACH (const QHostAddress &address, info.addresses()) { + if (!isSpecialAddress(address) && isIPv4Address(address)) { + hasResolvableIPv4Address = true; + break; + } + } + + return engine->toScriptValue(hasResolvableIPv4Address); + } catch (const Address::Error &) { + return engine->toScriptValue(false); + } +} + +// isPlainHostName(host) +// @returns true if @p host doesn't contains a domain part +QScriptValue ProxyPacParser::isPlainHostName(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + return engine->toScriptValue(context->argument(0).toString().indexOf(QLatin1Char('.')) == -1); +} + + +// isResolvableEx(host) +// @returns true if host is resolvable to an IPv4 or IPv6 address. +QScriptValue ProxyPacParser::isResolvableEx(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + + try { + const Address info = Address::resolve(context->argument(0).toString()); + bool hasResolvableIPAddress = false; + Q_FOREACH (const QHostAddress &address, info.addresses()) { + if (isIPv4Address(address) || isIPv6Address(address)) { + hasResolvableIPAddress = true; + break; + } + } + return engine->toScriptValue(hasResolvableIPAddress); + } catch (const Address::Error &) { + return engine->toScriptValue(false); + } +} + +// isInNetEx(ipAddress, ipPrefix ) +// @returns true if ipAddress is within the specified ipPrefix. +QScriptValue ProxyPacParser::isInNetEx(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 2) { + return engine->undefinedValue(); + } + + try { + const Address info = Address::resolve(context->argument(0).toString()); + bool isInSubNet = false; + const QString subnetStr = context->argument(1).toString(); + const QPair subnet = QHostAddress::parseSubnet(subnetStr); + + Q_FOREACH (const QHostAddress &address, info.addresses()) { + if (isSpecialAddress(address)) { + continue; + } + + if (address.isInSubnet(subnet)) { + isInSubNet = true; + break; + } + } + return engine->toScriptValue(isInSubNet); + } catch (const Address::Error &) { + return engine->toScriptValue(false); + } +} + + +// dnsResolveEx(host) +// @returns a semi-colon delimited string containing IPv6 and IPv4 addresses +// for host or an empty string if host is not resolvable. +QScriptValue ProxyPacParser::dnsResolveEx(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + + try { + const Address info = Address::resolve(context->argument(0).toString()); + + QStringList addressList; + QString resolvedAddress(QLatin1String("")); + + Q_FOREACH (const QHostAddress &address, info.addresses()) { + if (!isSpecialAddress(address)) { + addressList << address.toString(); + } + } + if (!addressList.isEmpty()) { + resolvedAddress = addressList.join(QLatin1String(";")); + } + + return engine->toScriptValue(resolvedAddress); + } catch (const Address::Error &) { + return engine->toScriptValue(QString(QLatin1String(""))); + } +} + +// myIpAddressEx() +// @returns a semi-colon delimited string containing all IP addresses for localhost (IPv6 and/or IPv4), +// or an empty string if unable to resolve localhost to an IP address. +QScriptValue ProxyPacParser::myIpAddressEx(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount()) { + return engine->undefinedValue(); + } + + QStringList ipAddressList; + const QList addresses = QNetworkInterface::allAddresses(); + Q_FOREACH (const QHostAddress address, addresses) { + if (!isSpecialAddress(address) && !isLocalHostAddress(address)) { + ipAddressList << address.toString(); + } + } + + return engine->toScriptValue(ipAddressList.join(QLatin1String(";"))); +} + +// sortIpAddressList(ipAddressList) +// @returns a sorted ipAddressList. If both IPv4 and IPv6 addresses are present in +// the list. The sorted IPv6 addresses will precede the sorted IPv4 addresses. +QScriptValue ProxyPacParser::sortIpAddressList(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return engine->undefinedValue(); + } + + QHash actualEntryMap; + QList ipV4List, ipV6List; + const QStringList ipAddressList = context->argument(0).toString().split(QLatin1Char(';')); + + Q_FOREACH (const QString &ipAddress, ipAddressList) { + QHostAddress address(ipAddress); + switch (address.protocol()) { + case QAbstractSocket::IPv4Protocol: + ipV4List << address; + actualEntryMap.insert(address.toString(), ipAddress); + break; + case QAbstractSocket::IPv6Protocol: + ipV6List << address; + actualEntryMap.insert(address.toString(), ipAddress); + break; + default: + break; + } + } + + QString sortedAddress(QLatin1String("")); + + if (!ipV6List.isEmpty()) { + qSort(ipV6List.begin(), ipV6List.end(), addressLessThanComparison); + sortedAddress += addressListToString(ipV6List, actualEntryMap); + } + + if (!ipV4List.isEmpty()) { + qSort(ipV4List.begin(), ipV4List.end(), addressLessThanComparison); + if (!sortedAddress.isEmpty()) { + sortedAddress += QLatin1Char(';'); + } + sortedAddress += addressListToString(ipV4List, actualEntryMap); + } + + return engine->toScriptValue(sortedAddress); + +} diff --git a/src/Core/network/proxypacparser.h b/src/Core/network/proxypacparser.h new file mode 100644 --- /dev/null +++ b/src/Core/network/proxypacparser.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef PROXYPACPARSER_H +#define PROXYPACPARSER_H + +#include +#include +#include + +class ProxyPacParser : public QObject +{ + Q_OBJECT + Q_PROPERTY( QString PacFile WRITE setPacFile ) + +public: + ProxyPacParser(QObject *parent = 0); + ~ProxyPacParser(); + void setPacFile(const QString& fileContent); + Q_SCRIPTABLE QString findProxyForUrl( const QString &url, const QString &host ); + +signals: + +public slots: +private: + + //Hostname based conditions: + static QScriptValue isPlainHostName( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue dnsDomainIs( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue localHostOrDomainIs( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue isResolvable( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue isInNet( QScriptContext *context, QScriptEngine *engine ); + + //Related utility functions: + static QScriptValue dnsResolve( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue myIpAddress( QScriptContext *context, QScriptEngine *engine ); + static QScriptValue dnsDomainLevels( QScriptContext *context, QScriptEngine *engine ); + + //URL/hostname based conditions: + static QScriptValue shExpMatch( QScriptContext *context, QScriptEngine *engine ); + + // Time based conditions: + static QScriptValue weekdayRange(QScriptContext *context, QScriptEngine *engine ); + static QScriptValue dateRange(QScriptContext *context, QScriptEngine *engine ); + static QScriptValue timeRange(QScriptContext *context, QScriptEngine *engine ); + + /* + * Implementation of Microsoft's IPv6 Extension for PAC + * + * Documentation: + * http://msdn.microsoft.com/en-us/library/gg308477(v=vs.85).aspx + * http://msdn.microsoft.com/en-us/library/gg308478(v=vs.85).aspx + * http://msdn.microsoft.com/en-us/library/gg308474(v=vs.85).aspx + * http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx + * + * taken from KDE KIO kpac source code :) + */ + static QScriptValue isResolvableEx(QScriptContext *context, QScriptEngine *engine); + static QScriptValue isInNetEx(QScriptContext *context, QScriptEngine *engine); + static QScriptValue dnsResolveEx(QScriptContext *context, QScriptEngine *engine); + static QScriptValue myIpAddressEx(QScriptContext *context, QScriptEngine *engine); + static QScriptValue sortIpAddressList(QScriptContext *context, QScriptEngine *engine); + + + QScriptEngine* engine; + + static int findString(const QString &s, const char * const *values); + static const QDateTime getTime(QScriptContext *context); +}; + +#endif // PROXYPACPARSER_H diff --git a/src/Core/network/qlopnetworkproxyfactory.cpp b/src/Core/network/qlopnetworkproxyfactory.cpp new file mode 100644 --- /dev/null +++ b/src/Core/network/qlopnetworkproxyfactory.cpp @@ -0,0 +1,171 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "qlopnetworkproxyfactory.h" +#include +#include +#include + +QLopNetworkProxyFactory::QLopNetworkProxyFactory() + :QNetworkProxyFactory() +{ + p_pacParser = new ProxyPacParser(); +} + +QLopNetworkProxyFactory::~QLopNetworkProxyFactory() +{ + +} + + +QList QLopNetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query) +{ + QList result; + switch (proxyCfgType) + { + case none: + result << QNetworkProxy(QNetworkProxy::NoProxy); + return result; + break; + case manual: + return queryProxy_manual(query); + break; + case system: + return queryProxy_system(query); + break; + case automatic: + return queryProxy_auto(query); + break; + default: + result << QNetworkProxy(QNetworkProxy::DefaultProxy); + return result; + break; + } +} + + +//should hanlde ignored hosts +QList QLopNetworkProxyFactory::queryProxy_manual(const QNetworkProxyQuery &query) +{ + QList result; + QString scheme = query.url().scheme(); + QHostInfo peerHost = QHostInfo::fromName(query.peerHostName()); + if(scheme=="http") + { + result.append(p_http_proxy); + } + if(scheme=="https") + { + result.append(p_https_proxy); + } + if(scheme=="ftp") + { + result.append(p_ftp_proxy); + } + result << QNetworkProxy(QNetworkProxy::DefaultProxy); + return result; +} + +QList QLopNetworkProxyFactory::queryProxy_system(const QNetworkProxyQuery &query) +{ + QList result; + result << QNetworkProxy(QNetworkProxy::DefaultProxy); + return result; +} + +QList QLopNetworkProxyFactory::queryProxy_auto(const QNetworkProxyQuery &query) +{ + QList result; + QString config=p_pacParser->findProxyForUrl(query.url().toString(),QHostInfo::localHostName()); + QStringList proxyList=config.split(";"); + for(int i=0;i=2) + { //TODO check correct syntax for pac returned proxy cfg + if(line.at(0).compare("PROXY",Qt::CaseInsensitive)) + { + QStringList proxyArgs=line.at(1).split(":"); + if(proxyArgs.count()>=2) + { + result << QNetworkProxy(QNetworkProxy::HttpProxy,proxyArgs.at(0),proxyArgs.at(1).toUInt()); + } + } + else if (line.at(0).compare("SOCKS",Qt::CaseInsensitive)) + { + QStringList proxyArgs=line.at(1).split(":"); + if(proxyArgs.count()>=2) + { + result << QNetworkProxy(QNetworkProxy::Socks5Proxy,proxyArgs.at(0),proxyArgs.at(1).toUInt()); + } + } + else + { + result << QNetworkProxy(QNetworkProxy::NoProxy); + } + } + else + { + result << QNetworkProxy(QNetworkProxy::NoProxy); + } + } + return result; +} + +void QLopNetworkProxyFactory::reloadConfig() +{ + QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString(); + if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_NONE)) + { + this->proxyCfgType = none; + } + else + if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_MANUAL)) + { + this->proxyCfgType = manual; + QString host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY).toString(); + QString port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY).toString(); + this->p_http_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); + + host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY).toString(); + port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY).toString(); + this->p_https_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); + + host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY).toString(); + port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY).toString(); + this->p_ftp_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); + + host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY).toString(); + port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY).toString(); + this->p_socks_proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy,host,port.toUInt()); + + } + else + if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_SYSTEM)) + { + this->proxyCfgType = system; + } + else + if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_AUTOMATIC)) + { + this->proxyCfgType = automatic; + } +} diff --git a/src/Core/network/qlopnetworkproxyfactory.h b/src/Core/network/qlopnetworkproxyfactory.h new file mode 100644 --- /dev/null +++ b/src/Core/network/qlopnetworkproxyfactory.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the QLop Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef QLOPNETWORKPROXYFACTORY_H +#define QLOPNETWORKPROXYFACTORY_H + +#include +#include +#include +#include + +#define CFG_PROXY_TYPE_ENTRY "proxy/type" +#define CFG_PROXY_TYPE_VALUE_NONE "none" +#define CFG_PROXY_TYPE_VALUE_MANUAL "manual" +#define CFG_PROXY_TYPE_VALUE_SYSTEM "system" +#define CFG_PROXY_TYPE_VALUE_AUTOMATIC "automatic" +#define CFG_PROXY_HTTP_HOST_ENTRY "proxy/http/host" +#define CFG_PROXY_HTTP_PORT_ENTRY "proxy/http/port" +#define CFG_PROXY_HTTPS_HOST_ENTRY "proxy/https/host" +#define CFG_PROXY_HTTPS_PORT_ENTRY "proxy/https/port" +#define CFG_PROXY_FTP_HOST_ENTRY "proxy/ftp/host" +#define CFG_PROXY_FTP_PORT_ENTRY "proxy/ftp/port" +#define CFG_PROXY_SOCKS_HOST_ENTRY "proxy/socks/host" +#define CFG_PROXY_SOCKS_PORT_ENTRY "proxy/socks/port" + +#define CFG_PROXY_IGNORE_HOSTS_ENTRY "proxy/ignore_hosts" + + + +class QLopNetworkProxyFactory : public QNetworkProxyFactory +{ +public: + QLopNetworkProxyFactory(); + ~QLopNetworkProxyFactory(); + + QList queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()); + QList queryProxy_manual(const QNetworkProxyQuery &query = QNetworkProxyQuery()); + QList queryProxy_system(const QNetworkProxyQuery &query = QNetworkProxyQuery()); + QList queryProxy_auto(const QNetworkProxyQuery &query = QNetworkProxyQuery()); + + void reloadConfig(); +private: + typedef enum proxyCfgType_t + { + none=0, + manual=1, + system=2, + automatic=3 + }proxyCfgType_t; + proxyCfgType_t proxyCfgType; + +//======================================================================= +// MANUAL PROXY CFG +//======================================================================= + QNetworkProxy p_http_proxy,p_https_proxy,p_ftp_proxy,p_socks_proxy; + QList p_ignoreHosts; + ProxyPacParser* p_pacParser; +}; + +#endif // QLOPNETWORKPROXYFACTORY_H diff --git a/src/Core/pythongenerator.sh b/src/Core/pythongenerator.sh --- a/src/Core/pythongenerator.sh +++ b/src/Core/pythongenerator.sh @@ -3,4 +3,4 @@ #export QTDIR=/usr/include #export QTDIR=/usr/include/qt5 -pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt +pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./network:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt diff --git a/src/Core/qlopsettings.cpp b/src/Core/qlopsettings.cpp --- a/src/Core/qlopsettings.cpp +++ b/src/Core/qlopsettings.cpp @@ -79,7 +79,7 @@ QLopSettings *QLopSettings::self() return _self; } -void QLopSettings::popConfigDialog(QWidget *selectedConfigEntry) +void QLopSettings::popConfigDialog(QLopSettingsItem *selectedConfigEntry) { INIT(); m_configDialog->popConfigDialog(selectedConfigEntry); @@ -90,9 +90,21 @@ void QLopSettings::popConfigDialog() m_configDialog->popConfigDialog(NULL); } -bool QLopSettings::registerConfigEntry(QWidget *configEntry, QIcon icon, QString text) +bool QLopSettings::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text) { INIT(); return m_configDialog->registerConfigEntry(configEntry, icon, text); } +void QLopSettings::setValue(QLopService* service, const QString &key, const QVariant &value) +{ + INIT(); + m_settings->setValue(service->serviceName()+"/"+key,value); +} + +QVariant QLopSettings::value(QLopService* service, const QString &key, const QVariant &defaultValue) +{ + INIT(); + return m_settings->value(service->serviceName()+"/"+key,defaultValue); +} + diff --git a/src/Core/qlopsettings.h b/src/Core/qlopsettings.h --- a/src/Core/qlopsettings.h +++ b/src/Core/qlopsettings.h @@ -44,8 +44,10 @@ public: static void init(bool noGUI=false,QObject *parent = 0); const QString& serviceName(); static QLopSettings* self(); - static void popConfigDialog(QWidget* selectedConfigEntry); - static bool registerConfigEntry(QWidget* configEntry,QIcon icon, QString text); + static void popConfigDialog(QLopSettingsItem *selectedConfigEntry); + static bool registerConfigEntry(QLopSettingsItem* configEntry,QIcon icon, QString text); + static void setValue(QLopService* service,const QString & key, const QVariant & value); + static QVariant value(QLopService* service, const QString & key, const QVariant & defaultValue = QVariant()); public slots: void popConfigDialog(); }; diff --git a/src/SocExplorerPlot.cpp b/src/SocExplorerPlot.cpp --- a/src/SocExplorerPlot.cpp +++ b/src/SocExplorerPlot.cpp @@ -45,6 +45,8 @@ SocExplorerPlot::SocExplorerPlot(QWidget this->m_plot->setNoAntialiasingOnDrag(true); this->show(); this->m_plot->legend->setVisible(true); + this->m_plot->plotLayout()->insertRow(0); + this->m_plotTitle = new QCPPlotTitle(m_plot); } SocExplorerPlot::~SocExplorerPlot() @@ -104,6 +106,8 @@ void SocExplorerPlot::setTitle(QString t /*! @todo Function borcken fixe this! */ + m_plotTitle->setText(title); + m_plot->plotLayout()->addElement(0, 0, m_plotTitle); this->m_Title = title; emit titleChanged(title); this->repaint(); diff --git a/src/SocExplorerPlot.h b/src/SocExplorerPlot.h --- a/src/SocExplorerPlot.h +++ b/src/SocExplorerPlot.h @@ -128,6 +128,7 @@ private: QPoint mOrigin; QList m_actions; QString m_Title; + QCPPlotTitle* m_plotTitle; int m_PID; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,11 +37,6 @@ #include -const QListServicesToLoad=QList() - <progressThreadIds[i] = -1; } this->progressWidget->setWindowTitle("Loading File"); + const QListServicesToLoad=QList() + <serviceName();