From 5351922440c0161096e3607c5385efb93fadb2eb Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 15 Jul 2018 18:54:29 +0200 Subject: [PATCH] Enabled minimum build configuration Minimum build configuration is without Qt, Ruby, curl and expat. Only Python is required. This commit also provides a functional (through polling) Qt-less HTTP implementation through libcurl if enabled. --- build.sh | 35 ++++--- src/pymod/__init__.py.noqt | 4 +- src/pymod/__init__.py.qt4 | 4 +- src/pymod/__init__.py.qt5 | 4 +- src/pymod/__init__.py.qtless | 5 + src/pymod/tl/tl.pro | 6 +- src/rbastub/rba.cc | 2 +- src/tl/tl/tl.pro | 5 + src/tl/tl/tlHttpStream.h | 107 ++++++++++++++++++++-- src/tl/tl/tlHttpStreamCurl.cc | 146 ++++++++++++++++++++++++------ src/tl/tl/tlHttpStreamCurl.h | 13 +-- src/tl/tl/tlHttpStreamNoQt.cc | 133 +++++++++++++++++++++++++++ src/tl/tl/tlHttpStreamQt.cc | 133 +++++++++++++++++++++++---- src/tl/tl/tlHttpStreamQt.h | 78 +--------------- src/tl/tl/tlXMLParser.cc | 106 ++++++++++++++++++++++ src/tl/unit_tests/tlHttpStream.cc | 4 + src/tl/unit_tests/tlWebDAV.cc | 4 + src/tl/unit_tests/tlXMLParser.cc | 5 +- 18 files changed, 638 insertions(+), 156 deletions(-) create mode 100644 src/pymod/__init__.py.qtless create mode 100644 src/tl/tl/tlHttpStreamNoQt.cc diff --git a/build.sh b/build.sh index 5bce6caaa..7d509a04a 100755 --- a/build.sh +++ b/build.sh @@ -26,9 +26,9 @@ IS_MAC="no" HAVE_QTBINDINGS=1 HAVE_64BIT_COORD=0 HAVE_QT=1 -HAVE_QT5="" -HAVE_CURL="" -HAVE_EXPAT="" +HAVE_QT5="" # not set +HAVE_CURL=0 +HAVE_EXPAT=0 RUBYINCLUDE="" RUBYINCLUDE2="" @@ -198,9 +198,10 @@ while [ "$*" != "" ]; do echo " -with-qtbinding Create Qt bindings for ruby scripts [default]" echo " -without-qtbinding Don't create Qt bindings for ruby scripts" echo " -with-64bit-coord Use long (64bit) coordinates - EXPERIMENTAL FEATURE" - echo " (only available for gcc>=4.4 for 64bit build)" + echo " (only available for gcc>=4.4 for 64bit build)" echo " -without-64bit-coord Don't use long (64bit) coordinates [default]" echo " -without-qt Qt-less build of the core libraries (including pymod)" + echo " (implies -without-qtbinding)" echo "" echo " -dry-run Don't build, just run qmake" echo "" @@ -210,7 +211,7 @@ while [ "$*" != "" ]; do echo "" echo " -rblib Location of the .so/.dll to link for Ruby support" echo " -rbinc Location of the Ruby headers (in particular 'ruby.h')" - echo " -rbinc and -rblib must be set to enable Ruby support" + echo " -rbinc and -rblib must be set to enable Ruby support" echo " -rbinc2 Second include path for Ruby 1.9 (containing 'ruby/config.h')" echo " -rbvers Ruby version code" echo "" @@ -268,11 +269,6 @@ if [ "$HAVE_QT5" = "" ]; then fi echo "Using qmake: $QMAKE" -if [ "$HAVE_QT5" != "0" ]; then - echo " Using Qt 5 API" -else - echo " Using Qt 4 API" -fi echo "" # if not given, locate ruby interpreter (prefer 1.9, then default, finally 1.8 as fallback) @@ -431,13 +427,30 @@ if [ "$PYTHON" != "" ] && [ "$PYTHON" != "-" ]; then fi +if [ $HAVE_QT = 0 ]; then + HAVE_QTBINDINGS=0 +fi + echo "Features:" +if [ $HAVE_QT = 0 ]; then + echo " Qt not used at all" +fi if [ $HAVE_QTBINDINGS != 0 ]; then - echo " Qt bindings enabled" + if [ "$HAVE_QT5" != "0" ]; then + echo " Qt bindings enabled (Qt 5 API)" + else + echo " Qt bindings enabled (Qt 4 API)" + fi fi if [ $HAVE_64BIT_COORD != 0 ]; then echo " 64 bit coordinates enabled" fi +if [ $HAVE_EXPAT != 0 ]; then + echo " Uses libexpat for XML parsing" +fi +if [ $HAVE_CURL != 0 ]; then + echo " Uses libcurl for network access" +fi if [ "$RPATH" = "" ]; then RPATH="$BIN" fi diff --git a/src/pymod/__init__.py.noqt b/src/pymod/__init__.py.noqt index 83b190ba0..dce96f8e4 100644 --- a/src/pymod/__init__.py.noqt +++ b/src/pymod/__init__.py.noqt @@ -1,5 +1,5 @@ -# pykl library definition file +# klayout library definition file -__all__ = [ "tl", "db", "lay" ] +__all__ = [ "tl", "db", "lay", "rdb" ] diff --git a/src/pymod/__init__.py.qt4 b/src/pymod/__init__.py.qt4 index bd01416e4..8fee0a23c 100644 --- a/src/pymod/__init__.py.qt4 +++ b/src/pymod/__init__.py.qt4 @@ -1,5 +1,5 @@ -# pykl library definition file +# klayout library definition file -__all__ = [ "tl", "db", "lay", "QtCore", "QtGui", "QtXml", "QtSql", "QtNetwork", "QtDesigner" ] +__all__ = [ "tl", "db", "lay", "rdb", "QtCore", "QtGui", "QtXml", "QtSql", "QtNetwork", "QtDesigner" ] diff --git a/src/pymod/__init__.py.qt5 b/src/pymod/__init__.py.qt5 index 6315cf1d8..6e23c9122 100644 --- a/src/pymod/__init__.py.qt5 +++ b/src/pymod/__init__.py.qt5 @@ -1,7 +1,7 @@ -# pykl library definition file +# klayout library definition file -__all__ = [ "tl", "db", "lay", +__all__ = [ "tl", "db", "lay", "rdb", "QtCore", "QtGui", "QtNetwork", "QtSql", "QtWidgets", "QtDesigner", "QtMultimedia", "QtPrintSupport", "QtSvg", "QtXmlPatterns", "QtXml" ] diff --git a/src/pymod/__init__.py.qtless b/src/pymod/__init__.py.qtless new file mode 100644 index 000000000..dce96f8e4 --- /dev/null +++ b/src/pymod/__init__.py.qtless @@ -0,0 +1,5 @@ + +# klayout library definition file + +__all__ = [ "tl", "db", "lay", "rdb" ] + diff --git a/src/pymod/tl/tl.pro b/src/pymod/tl/tl.pro index b6093d661..30b549504 100644 --- a/src/pymod/tl/tl.pro +++ b/src/pymod/tl/tl.pro @@ -17,7 +17,11 @@ equals(HAVE_QTBINDINGS, "1") { INIT_PY = $$PWD/../__init__.py.qt4 } } else { - INIT_PY = $$PWD/../__init__.py.noqt + equals(HAVE_QT, "0") { + INIT_PY = $$PWD/../__init__.py.qtless + } else { + INIT_PY = $$PWD/../__init__.py.noqt + } } QMAKE_POST_LINK += && $(COPY) $$INIT_PY $$DESTDIR_PYMOD/__init__.py diff --git a/src/rbastub/rba.cc b/src/rbastub/rba.cc index 71718be2b..def836aa7 100644 --- a/src/rbastub/rba.cc +++ b/src/rbastub/rba.cc @@ -27,7 +27,7 @@ namespace rba static void fail (const char *file, int line) { - throw tl::ScriptError (tl::to_string (QObject::tr ("Ruby support not compiled in")).c_str (), file, line, "missing_feature", std::vector ()); + throw tl::ScriptError (tl::to_string (tr ("Ruby support not compiled in")).c_str (), file, line, "missing_feature", std::vector ()); } static RubyInterpreter *sp_rba_interpreter = 0; diff --git a/src/tl/tl/tl.pro b/src/tl/tl/tl.pro index b1b8a6535..e13891ebd 100644 --- a/src/tl/tl/tl.pro +++ b/src/tl/tl/tl.pro @@ -131,6 +131,11 @@ equals(HAVE_CURL, "1") { tlHttpStreamQt.cc \ tlWebDAV.cc \ + } else { + + SOURCES += \ + tlHttpStreamNoQt.cc \ + } } diff --git a/src/tl/tl/tlHttpStream.h b/src/tl/tl/tlHttpStream.h index 8f9fa536c..7d17b0603 100644 --- a/src/tl/tl/tlHttpStream.h +++ b/src/tl/tl/tlHttpStream.h @@ -23,14 +23,10 @@ #ifndef HDR_tlHttpStream #define HDR_tlHttpStream -#if defined(HAVE_CURL) -# include "tlHttpStreamCurl.h" -#elif defined(HAVE_QT) -# include "tlHttpStreamQt.h" -#endif - #include "tlObject.h" #include "tlException.h" +#include "tlStream.h" +#include "tlEvents.h" namespace tl { @@ -63,6 +59,105 @@ public: { } }; +class InputHttpStreamPrivateData; + +/** + * @brief A http input delegate for tl::InputStream + * + * Implements the reader from a server using the HTTP protocol + */ +class TL_PUBLIC InputHttpStream + : public InputStreamBase +{ +public: + /** + * @brief Open a stream with the given URL + */ + InputHttpStream (const std::string &url); + + /** + * @brief Close the file + * + * The destructor will automatically close the connection. + */ + virtual ~InputHttpStream (); + + /** + * @brief Sets the credential provider + */ + static void set_credential_provider (HttpCredentialProvider *cp); + + /** + * @brief Sends the request for data + * To ensure prompt delivery of data, this method can be used prior to + * "read" to trigger the download from the given URL. + * This method will return immediately. When the reply is available, + * the "ready" event will be triggered. "read" can then be used to + * read the data or - in case of an error - throw an exception. + * If "send" is not used before "read", "read" will block until data + * is available. + * If a request has already been sent, this method will do nothing. + */ + void send (); + + /** + * @brief Closes the connection + */ + void close (); + + /** + * @brief Sets the request verb + * The default verb is "GET" + */ + void set_request (const char *r); + + /** + * @brief Sets data to be sent with the request + * If data is given, it is sent along with the request. + * This version takes a null-terminated string. + */ + void set_data (const char *data); + + /** + * @brief Sets data to be sent with the request + * If data is given, it is sent along with the request. + * This version takes a data plus length. + */ + void set_data (const char *data, size_t n); + + /** + * @brief Sets a header field + */ + void add_header (const std::string &name, const std::string &value); + + /** + * @brief Gets the "ready" event + * Connect to this event for the asynchroneous interface. + * This event is fired when data becomes available or the + * connection has terminated with an error. + */ + tl::Event &ready (); + + /** + * @brief Gets a value indicating whether data is available + */ + bool data_available (); + + /** + * @brief Read from the stream + * Implements the basic read method. + */ + virtual size_t read (char *b, size_t n); + + virtual void reset (); + virtual std::string source () const; + virtual std::string absolute_path () const; + virtual std::string filename () const; + +private: + InputHttpStreamPrivateData *mp_data; +}; + } #endif diff --git a/src/tl/tl/tlHttpStreamCurl.cc b/src/tl/tl/tlHttpStreamCurl.cc index c29b79467..a9d7ceb82 100644 --- a/src/tl/tl/tlHttpStreamCurl.cc +++ b/src/tl/tl/tlHttpStreamCurl.cc @@ -543,6 +543,105 @@ private: static CurlNetworkManager *ms_instance; }; +// --------------------------------------------------------------- +// InputHttpStream implementation + +InputHttpStream::InputHttpStream (const std::string &url) +{ + mp_data = new InputHttpStreamPrivateData (url); +} + +InputHttpStream::~InputHttpStream () +{ + delete mp_data; + mp_data = 0; +} + +void +InputHttpStream::set_credential_provider (HttpCredentialProvider *cp) +{ + CurlNetworkManager::instance ()->credentials ().set_provider (cp); + CurlNetworkManager::instance ()->proxy_credentials ().set_provider (cp); +} + +void +InputHttpStream::send () +{ + mp_data->send (); +} + +void +InputHttpStream::close () +{ + mp_data->close (); +} + +void +InputHttpStream::set_request (const char *r) +{ + mp_data->set_request (r); +} + +void +InputHttpStream::set_data (const char *data) +{ + mp_data->set_data (data); +} + +void +InputHttpStream::set_data (const char *data, size_t n) +{ + mp_data->set_data (data, n); +} + +void +InputHttpStream::add_header (const std::string &name, const std::string &value) +{ + mp_data->add_header (name, value); +} + +tl::Event & +InputHttpStream::ready () +{ + return mp_data->ready (); +} + +bool +InputHttpStream::data_available () +{ + return mp_data->data_available (); +} + +size_t +InputHttpStream::read (char *b, size_t n) +{ + return mp_data->read (b, n); +} + +void +InputHttpStream::reset () +{ + mp_data->reset (); +} + +std::string +InputHttpStream::source () const +{ + return mp_data->source (); +} + +std::string +InputHttpStream::absolute_path () const +{ + return mp_data->absolute_path (); +} + +std::string +InputHttpStream::filename () const +{ + return mp_data->filename (); +} + // ---------------------------------------------------------------------- // CurlConnection implementation @@ -1072,63 +1171,63 @@ int CurlNetworkManager::tick () } // --------------------------------------------------------------- -// InputHttpFileCurl implementation +// InputHttpStreamPrivateData implementation -InputHttpStream::InputHttpStream (const std::string &url) +InputHttpStreamPrivateData::InputHttpStreamPrivateData (const std::string &url) { m_sent = false; m_ready = false; m_connection.reset (CurlNetworkManager::instance ()->create_connection ()); m_connection->set_url (url.c_str ()); - m_connection->data_available_event.add (this, &InputHttpStream::on_data_available); - m_connection->finished_event.add (this, &InputHttpStream::on_finished); + m_connection->data_available_event.add (this, &InputHttpStreamPrivateData::on_data_available); + m_connection->finished_event.add (this, &InputHttpStreamPrivateData::on_finished); } -InputHttpStream::~InputHttpStream () +InputHttpStreamPrivateData::~InputHttpStreamPrivateData () { // .. nothing yet .. } bool -InputHttpStream::data_available () +InputHttpStreamPrivateData::data_available () { return m_connection->read_available () > 0; } void -InputHttpStream::set_request (const char *r) +InputHttpStreamPrivateData::set_request (const char *r) { m_connection->set_request (r); } void -InputHttpStream::set_data (const char *data) +InputHttpStreamPrivateData::set_data (const char *data) { m_connection->set_data (data); } void -InputHttpStream::set_data (const char *data, size_t n) +InputHttpStreamPrivateData::set_data (const char *data, size_t n) { m_connection->set_data (data, n); } void -InputHttpStream::add_header (const std::string &name, const std::string &value) +InputHttpStreamPrivateData::add_header (const std::string &name, const std::string &value) { m_connection->add_header (name.c_str (), value.c_str ()); } void -InputHttpStream::on_finished () +InputHttpStreamPrivateData::on_finished () { m_progress.reset (0); m_ready_event (); } void -InputHttpStream::on_data_available () +InputHttpStreamPrivateData::on_data_available () { // send the ready event just once if (! m_ready) { @@ -1138,7 +1237,7 @@ InputHttpStream::on_data_available () } void -InputHttpStream::send () +InputHttpStreamPrivateData::send () { m_ready = false; m_progress.reset (0); @@ -1147,7 +1246,7 @@ InputHttpStream::send () } void -InputHttpStream::check () +InputHttpStreamPrivateData::check () { if (m_connection->finished ()) { m_connection->check (); @@ -1155,7 +1254,7 @@ InputHttpStream::check () } size_t -InputHttpStream::read (char *b, size_t n) +InputHttpStreamPrivateData::read (char *b, size_t n) { if (! m_sent) { send (); @@ -1185,7 +1284,7 @@ InputHttpStream::read (char *b, size_t n) } void -InputHttpStream::close () +InputHttpStreamPrivateData::close () { m_progress.reset (0); if (m_connection.get ()) { @@ -1195,34 +1294,27 @@ InputHttpStream::close () } void -InputHttpStream::reset () +InputHttpStreamPrivateData::reset () { throw tl::Exception (tl::to_string (tr ("'reset' is not supported on HTTP input streams"))); } std::string -InputHttpStream::filename () const +InputHttpStreamPrivateData::filename () const { return tl::filename (tl::URI (m_connection->url ()).path ()); } std::string -InputHttpStream::source () const +InputHttpStreamPrivateData::source () const { return m_connection->url (); } std::string -InputHttpStream::absolute_path () const +InputHttpStreamPrivateData::absolute_path () const { return m_connection->url (); } -void -InputHttpStream::set_credential_provider (HttpCredentialProvider *cp) -{ - CurlNetworkManager::instance ()->credentials ().set_provider (cp); - CurlNetworkManager::instance ()->proxy_credentials ().set_provider (cp); -} - } diff --git a/src/tl/tl/tlHttpStreamCurl.h b/src/tl/tl/tlHttpStreamCurl.h index 3d17517af..784d1875b 100644 --- a/src/tl/tl/tlHttpStreamCurl.h +++ b/src/tl/tl/tlHttpStreamCurl.h @@ -41,26 +41,21 @@ class HttpCredentialProvider; * * Implements the reader from a server using the HTTP protocol */ -class TL_PUBLIC InputHttpStream - : public tl::Object, public InputStreamBase +class TL_PUBLIC InputHttpStreamPrivateData + : public tl::Object { public: /** * @brief Open a stream with the given URL */ - InputHttpStream (const std::string &url); + InputHttpStreamPrivateData (const std::string &url); /** * @brief Close the file * * The destructor will automatically close the connection. */ - virtual ~InputHttpStream (); - - /** - * @brief Sets the credential provider - */ - static void set_credential_provider (HttpCredentialProvider *cp); + virtual ~InputHttpStreamPrivateData (); /** * @brief Sends the request for data diff --git a/src/tl/tl/tlHttpStreamNoQt.cc b/src/tl/tl/tlHttpStreamNoQt.cc new file mode 100644 index 000000000..88355a79a --- /dev/null +++ b/src/tl/tl/tlHttpStreamNoQt.cc @@ -0,0 +1,133 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "tlHttpStream.h" +#include "tlEvents.h" + +namespace tl +{ + +// --------------------------------------------------------------- +// Dummy InputHttpStream implementation + +InputHttpStream::InputHttpStream (const std::string &) +{ + tl_assert (false); +} + +InputHttpStream::~InputHttpStream () +{ + // .. nothing yet .. +} + +void +InputHttpStream::set_credential_provider (HttpCredentialProvider *) +{ + // .. nothing yet .. +} + +void +InputHttpStream::send () +{ + // .. nothing yet .. +} + +void +InputHttpStream::close () +{ + // .. nothing yet .. +} + +void +InputHttpStream::set_request (const char *) +{ + // .. nothing yet .. +} + +void +InputHttpStream::set_data (const char *) +{ + // .. nothing yet .. +} + +void +InputHttpStream::set_data (const char *, size_t) +{ + // .. nothing yet .. +} + +void +InputHttpStream::add_header (const std::string &, const std::string &) +{ + // .. nothing yet .. +} + +tl::Event & +InputHttpStream::ready () +{ + // .. nothing yet .. + static tl::Event dummy; + return dummy; +} + +bool +InputHttpStream::data_available () +{ + // .. nothing yet .. + return false; +} + +size_t +InputHttpStream::read (char *, size_t) +{ + // .. nothing yet .. + return 0; +} + +void +InputHttpStream::reset () +{ + // .. nothing yet .. +} + +std::string +InputHttpStream::source () const +{ + // .. nothing yet .. + return std::string (); +} + +std::string +InputHttpStream::absolute_path () const +{ + // .. nothing yet .. + return std::string (); +} + +std::string +InputHttpStream::filename () const +{ + // .. nothing yet .. + return std::string (); +} + +} diff --git a/src/tl/tl/tlHttpStreamQt.cc b/src/tl/tl/tlHttpStreamQt.cc index c1e8dfe23..fab1ad0ab 100644 --- a/src/tl/tl/tlHttpStreamQt.cc +++ b/src/tl/tl/tlHttpStreamQt.cc @@ -21,6 +21,7 @@ */ #include "tlHttpStream.h" +#include "tlHttpStreamQt.h" #include "tlLog.h" #include "tlStaticObjects.h" #include "tlDeferredExecution.h" @@ -88,12 +89,110 @@ AuthenticationHandler::proxyAuthenticationRequired (const QNetworkProxy &proxy, } // --------------------------------------------------------------- -// InputHttpFileQt implementation +// InputHttpStream implementation + +InputHttpStream::InputHttpStream (const std::string &url) +{ + mp_data = new InputHttpStreamPrivateData (url); +} + +InputHttpStream::~InputHttpStream () +{ + delete mp_data; + mp_data = 0; +} + +void +InputHttpStream::set_credential_provider (HttpCredentialProvider *cp) +{ + sp_credential_provider.reset (cp); +} + +void +InputHttpStream::send () +{ + mp_data->send (); +} + +void +InputHttpStream::close () +{ + mp_data->close (); +} + +void +InputHttpStream::set_request (const char *r) +{ + mp_data->set_request (r); +} + +void +InputHttpStream::set_data (const char *data) +{ + mp_data->set_data (data); +} + +void +InputHttpStream::set_data (const char *data, size_t n) +{ + mp_data->set_data (data, n); +} + +void +InputHttpStream::add_header (const std::string &name, const std::string &value) +{ + mp_data->add_header (name, value); +} + +tl::Event & +InputHttpStream::ready () +{ + return mp_data->ready (); +} + +bool +InputHttpStream::data_available () +{ + return mp_data->data_available (); +} + +size_t +InputHttpStream::read (char *b, size_t n) +{ + return mp_data->read (b, n); +} + +void +InputHttpStream::reset () +{ + mp_data->reset (); +} + +std::string +InputHttpStream::source () const +{ + return mp_data->source (); +} + +std::string +InputHttpStream::absolute_path () const +{ + return mp_data->absolute_path (); +} + +std::string +InputHttpStream::filename () const +{ + return mp_data->filename (); +} + +// --------------------------------------------------------------- +// InputHttpStreamPrivateData implementation static QNetworkAccessManager *s_network_manager (0); static AuthenticationHandler *s_auth_handler (0); -InputHttpStream::InputHttpStream (const std::string &url) +InputHttpStreamPrivateData::InputHttpStreamPrivateData (const std::string &url) : m_url (url), mp_reply (0), m_request ("GET"), mp_buffer (0) { if (! s_network_manager) { @@ -111,13 +210,13 @@ InputHttpStream::InputHttpStream (const std::string &url) connect (s_network_manager, SIGNAL (finished (QNetworkReply *)), this, SLOT (finished (QNetworkReply *))); } -InputHttpStream::~InputHttpStream () +InputHttpStreamPrivateData::~InputHttpStreamPrivateData () { close (); } void -InputHttpStream::close () +InputHttpStreamPrivateData::close () { if (mp_active_reply.get ()) { mp_active_reply->abort (); @@ -127,37 +226,31 @@ InputHttpStream::close () } void -InputHttpStream::set_credential_provider (HttpCredentialProvider *cp) -{ - sp_credential_provider.reset (cp); -} - -void -InputHttpStream::set_request (const char *r) +InputHttpStreamPrivateData::set_request (const char *r) { m_request = QByteArray (r); } void -InputHttpStream::set_data (const char *data) +InputHttpStreamPrivateData::set_data (const char *data) { m_data = QByteArray (data); } void -InputHttpStream::set_data (const char *data, size_t n) +InputHttpStreamPrivateData::set_data (const char *data, size_t n) { m_data = QByteArray (data, int (n)); } void -InputHttpStream::add_header (const std::string &name, const std::string &value) +InputHttpStreamPrivateData::add_header (const std::string &name, const std::string &value) { m_headers.insert (std::make_pair (name, value)); } void -InputHttpStream::finished (QNetworkReply *reply) +InputHttpStreamPrivateData::finished (QNetworkReply *reply) { if (reply != mp_active_reply.get ()) { return; @@ -177,7 +270,7 @@ InputHttpStream::finished (QNetworkReply *reply) } void -InputHttpStream::issue_request (const QUrl &url) +InputHttpStreamPrivateData::issue_request (const QUrl &url) { delete mp_buffer; mp_buffer = 0; @@ -216,7 +309,7 @@ InputHttpStream::issue_request (const QUrl &url) } void -InputHttpStream::send () +InputHttpStreamPrivateData::send () { if (mp_reply == 0) { issue_request (QUrl (tl::to_qstring (m_url))); @@ -224,7 +317,7 @@ InputHttpStream::send () } size_t -InputHttpStream::read (char *b, size_t n) +InputHttpStreamPrivateData::read (char *b, size_t n) { // Prevents deferred methods to be executed during the processEvents below (undesired side effects) tl::NoDeferredMethods silent; @@ -286,13 +379,13 @@ InputHttpStream::read (char *b, size_t n) } void -InputHttpStream::reset () +InputHttpStreamPrivateData::reset () { throw tl::Exception (tl::to_string (QObject::tr ("'reset' is not supported on HTTP input streams"))); } std::string -InputHttpStream::filename () const +InputHttpStreamPrivateData::filename () const { return tl::to_string (QFileInfo (QUrl (tl::to_qstring (m_url)).path ()).fileName ()); } diff --git a/src/tl/tl/tlHttpStreamQt.h b/src/tl/tl/tlHttpStreamQt.h index 1d4ecef78..6332ec81b 100644 --- a/src/tl/tl/tlHttpStreamQt.h +++ b/src/tl/tl/tlHttpStreamQt.h @@ -59,102 +59,34 @@ private: int m_retry, m_proxy_retry; }; -/** - * @brief A http input delegate for tl::InputStream - * - * Implements the reader from a server using the HTTP protocol - */ -class TL_PUBLIC InputHttpStream - : public QObject, public InputStreamBase +class InputHttpStreamPrivateData + : public QObject { Q_OBJECT public: - /** - * @brief Open a stream with the given URL - */ - InputHttpStream (const std::string &url); + InputHttpStreamPrivateData (const std::string &url); - /** - * @brief Close the file - * - * The destructor will automatically close the connection. - */ - virtual ~InputHttpStream (); + virtual ~InputHttpStreamPrivateData (); - /** - * @brief Sets the credential provider - */ - static void set_credential_provider (HttpCredentialProvider *cp); - - /** - * @brief Sends the request for data - * To ensure prompt delivery of data, this method can be used prior to - * "read" to trigger the download from the given URL. - * This method will return immediately. When the reply is available, - * the "ready" event will be triggered. "read" can then be used to - * read the data or - in case of an error - throw an exception. - * If "send" is not used before "read", "read" will block until data - * is available. - * If a request has already been sent, this method will do nothing. - */ void send (); - - /** - * @brief Closes the connection - */ void close (); - - /** - * @brief Sets the request verb - * The default verb is "GET" - */ void set_request (const char *r); - - /** - * @brief Sets data to be sent with the request - * If data is given, it is sent along with the request. - * This version takes a null-terminated string. - */ void set_data (const char *data); - - /** - * @brief Sets data to be sent with the request - * If data is given, it is sent along with the request. - * This version takes a data plus length. - */ void set_data (const char *data, size_t n); - - /** - * @brief Sets a header field - */ void add_header (const std::string &name, const std::string &value); - /** - * @brief Read from the stream - * Implements the basic read method. - */ - virtual size_t read (char *b, size_t n); - - /** - * @brief Gets the "ready" event - * Connect to this event for the asynchroneous interface. - * This event is fired when data becomes available or the - * connection has terminated with an error. - */ tl::Event &ready () { return m_ready; } - /** - * @brief Gets a value indicating whether data is available - */ bool data_available () { return mp_reply != 0; } + virtual size_t read (char *b, size_t n); virtual void reset (); virtual std::string source () const diff --git a/src/tl/tl/tlXMLParser.cc b/src/tl/tl/tlXMLParser.cc index 3b888d55b..399088aa5 100644 --- a/src/tl/tl/tlXMLParser.cc +++ b/src/tl/tl/tlXMLParser.cc @@ -763,6 +763,112 @@ XMLParser::parse (XMLSource &source, XMLStructureHandler &struct_handler) } +#else + +namespace tl +{ + +// -------------------------------------------------------------------- +// XMLSource implementation + +XMLSource::XMLSource () + : mp_source (0) +{ + // .. nothing yet .. +} + +XMLSource::~XMLSource () +{ + // .. nothing yet .. +} + +void +XMLSource::reset () +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------- +// XMLStringSource implementation + +XMLStringSource::XMLStringSource (const std::string &) +{ + tl_assert (false); +} + +XMLStringSource::XMLStringSource (const char *) +{ + tl_assert (false); +} + +XMLStringSource::XMLStringSource (const char *, size_t) +{ + tl_assert (false); +} + +XMLStringSource::~XMLStringSource () +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------- +// XMLFileSource implementation + +XMLFileSource::XMLFileSource (const std::string &, const std::string &) +{ + tl_assert (false); +} + +XMLFileSource::XMLFileSource (const std::string &) +{ + tl_assert (false); +} + +XMLFileSource::~XMLFileSource () +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------- +// XMLStreamSource implementation + +XMLStreamSource::XMLStreamSource (tl::InputStream &, const std::string &) +{ + tl_assert (false); +} + +XMLStreamSource::XMLStreamSource (tl::InputStream &) +{ + tl_assert (false); +} + +XMLStreamSource::~XMLStreamSource () +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------- +// XMLParser implementation + +XMLParser::XMLParser () + : mp_data (0) +{ + // .. nothing yet .. +} + +XMLParser::~XMLParser () +{ + // .. nothing yet .. +} + +void +XMLParser::parse (XMLSource &, XMLStructureHandler &) +{ + tl_assert (false); +} + +} + #endif namespace tl { diff --git a/src/tl/unit_tests/tlHttpStream.cc b/src/tl/unit_tests/tlHttpStream.cc index 029ffa5a3..cbfd6fe3a 100644 --- a/src/tl/unit_tests/tlHttpStream.cc +++ b/src/tl/unit_tests/tlHttpStream.cc @@ -25,6 +25,8 @@ #include "tlUnitTest.h" #include "tlTimer.h" +#if defined(HAVE_QT) || defined(HAVE_CURL) + #if defined(HAVE_QT) # include #endif @@ -119,3 +121,5 @@ TEST(3) } #endif + +#endif diff --git a/src/tl/unit_tests/tlWebDAV.cc b/src/tl/unit_tests/tlWebDAV.cc index 864e3586c..5f5c23c09 100644 --- a/src/tl/unit_tests/tlWebDAV.cc +++ b/src/tl/unit_tests/tlWebDAV.cc @@ -25,6 +25,8 @@ #include "tlUnitTest.h" #include "tlFileUtils.h" +#if defined(HAVE_QT) || defined(HAVE_CURL) + static std::string test_url1 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata"); static std::string test_url2 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/text"); @@ -121,3 +123,5 @@ TEST(5) EXPECT_EQ (ba21, "A text II.I.\n"); text21.close (); } + +#endif diff --git a/src/tl/unit_tests/tlXMLParser.cc b/src/tl/unit_tests/tlXMLParser.cc index ecc745b8f..68360c42a 100644 --- a/src/tl/unit_tests/tlXMLParser.cc +++ b/src/tl/unit_tests/tlXMLParser.cc @@ -20,11 +20,11 @@ */ - - #include "tlXMLParser.h" #include "tlUnitTest.h" +#if defined(HAVE_QT) || defined(HAVE_EXPAT) + #include #include @@ -652,3 +652,4 @@ TEST (13) EXPECT_EQ (child.txt, "H\xc3\xa4llo"); } +#endif