summaryrefslogtreecommitdiff
path: root/client/netcom.cc
diff options
context:
space:
mode:
authordeva <deva>2010-02-12 13:47:10 +0000
committerdeva <deva>2010-02-12 13:47:10 +0000
commit305ddf3bdb16177420f480b006550508174a734e (patch)
tree193f4a72f10e3194dc188e75fbf70e1c5c795fac /client/netcom.cc
parent85584af165fdcabac284addeba2461af08de8b75 (diff)
Revert to old protocol
Diffstat (limited to 'client/netcom.cc')
-rw-r--r--client/netcom.cc122
1 files changed, 34 insertions, 88 deletions
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 <QtNetwork>
-
#include <QApplication>
#include <QByteArray>
-#include <QHttp>
-
#include "widgets/widget.h"
-#ifdef USE_SSL
-#include <QMessageBox>
-#include <QList>
-#include <QSslError>
-#include <QSslSocket>
-
-#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<QSslError> &)),
- this, SLOT(sslError(const QList<QSslError> &)));
- 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<QSslError> &errlst)
-{
- QList<QSslError>::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