From 305ddf3bdb16177420f480b006550508174a734e Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 12 Feb 2010 13:47:10 +0000 Subject: Revert to old protocol --- client/netcom.cc | 122 ++++++++++++++++--------------------------------------- client/netcom.h | 21 +++------- 2 files changed, 40 insertions(+), 103 deletions(-) (limited to 'client') diff --git a/client/netcom.cc b/client/netcom.cc index 4126b02..3b3abb7 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -26,74 +26,31 @@ */ #include "netcom.h" -#include - #include #include -#include - #include "widgets/widget.h" -#ifdef USE_SSL -#include -#include -#include -#include - -#ifdef QT_NO_OPENSSL -#error "QT not compiled with SSL support." -#endif -#endif - NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) { this->user = user; this->cpr = cpr; - - connect(&http, SIGNAL(readyRead(const QHttpResponseHeader &)), - this, SLOT(readyRead(const QHttpResponseHeader &))); - connect(&http, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int))); - -#ifdef USE_SSL - connect(&http, SIGNAL(sslErrors(const QList &)), - this, SLOT(sslError(const QList &))); - http.setHost(host, QHttp::ConnectionModeHttps, port); -#else - http.setHost(host, QHttp::ConnectionModeHttp, port); -#endif - - transfering = false; - - QHttpRequestHeader h("HTTP 1.1", "/"); - http.request(h, ""); - - transfering = true; - buffer = ""; - do { - qApp->processEvents(QEventLoop::WaitForMoreEvents); - } while(transfering); - - sessionid = http.lastResponse().value("SessionID"); - printf("SESSION ID: %s\n", sessionid.toStdString().c_str()); + socket.connectToHost(host, port); + connect(&socket, SIGNAL(readyRead()), this, SLOT(readyRead())); + socket.waitForConnected(); + transmitting = false; } NetCom::~NetCom() { - QHttpRequestHeader h("HTTP 1.1", "/"); - h.setValue("SessionCommit", ""); - h.setValue("SessionID", sessionid); - http.request(h, ""); - - transfering = true; - buffer = ""; - do { - qApp->processEvents(QEventLoop::WaitForMoreEvents); - } while(transfering); + socket.disconnectFromHost(); } QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) { + printf("Socket state: %d\n", socket.state()); + if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str()); + if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(false); if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -115,17 +72,14 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) printf("\nSending request:\n%s", doc.toString().toStdString().c_str()); - QHttpRequestHeader h("HTTP 1.1", "/"); - h.setValue("SessionID", sessionid); - http.request(h, doc.toByteArray()); + socket.write(doc.toByteArray()); + // socket.waitForReadyRead(); - QDomDocument res_doc; - transfering = true; - buffer = ""; do { qApp->processEvents(QEventLoop::WaitForMoreEvents); - } while(transfering); - res_doc.setContent(buffer); + } while(!res_doc.setContent(buffer)); + + buffer = ""; QDomElement elem = res_doc.documentElement(); @@ -137,8 +91,18 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) return res_doc; } +void NetCom::readyRead() +{ + buffer.append(socket.readAll()); +} + void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QString version) { + printf("Socket state: %d\n", socket.state()); + if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str()); + + // if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false); // Moved down! + QDomDocument doc; QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); @@ -175,40 +139,22 @@ void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QStr printf("\nSending commit:\n%s", doc.toString().toStdString().c_str()); - QHttpRequestHeader h("HTTP 1.1", "/"); - h.setValue("SessionID", sessionid); - http.request(h, doc.toByteArray()); + socket.write(doc.toByteArray()); + // socket.waitForReadyRead(); - transfering = true; - buffer = ""; + // + // Wait for the (hopefully) empty answer. + // do { qApp->processEvents(QEventLoop::WaitForMoreEvents); - } while(transfering); + } while(!res_doc.setContent(buffer)); - QApplication::restoreOverrideCursor(); - if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true); -} + buffer = ""; -void NetCom::readyRead(const QHttpResponseHeader &) -{ - // printf("STATE: readyRead\n"); - buffer += http.readAll(); -} + //QDomElement elem = res_doc.documentElement(); -void NetCom::stateChanged(int state) -{ - // printf("STATE: %d\n", state); - if(transfering && state == QHttp::Connected) transfering = false; -} + printf("\nRecieved commit:\n%s", res_doc.toString().toStdString().c_str()); -#ifdef USE_SSL -void NetCom::sslError(const QList &errlst) -{ - QList::const_iterator i = errlst.begin(); - while(i != errlst.end()) { - QMessageBox::warning(qApp->activeWindow(), "SSL Error", i->errorString()); - i++; - } - http.ignoreSslErrors(); + QApplication::restoreOverrideCursor(); + if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true); } -#endif diff --git a/client/netcom.h b/client/netcom.h index 718d5a6..35db221 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -31,9 +31,6 @@ #include #include #include -#include - -//#define USE_SSL //#include "widgets/widget.h" class Widget; @@ -48,23 +45,17 @@ public: void send(QVector< Widget* > widgets, QString templ, QString macro, QString version); public slots: - void stateChanged(int state); - void readyRead(const QHttpResponseHeader &resp); - -#ifdef USE_SSL - void sslError(const QList &errlst); -#endif + void readyRead(); private: - volatile bool transfering; + volatile bool transmitting; + QTcpSocket socket; + + QByteArray buffer; + QDomDocument res_doc; QString user; QString cpr; - - QHttp http; - - QByteArray buffer; - QString sessionid; }; #endif/*__PRACRO_NETCOM_H__*/ -- cgit v1.2.3