summaryrefslogtreecommitdiff
path: root/agents/webproxyconn.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2016-01-01 22:05:42 +0100
committerJavier <dev.git@javispedro.com>2016-01-01 22:05:42 +0100
commita45977185a485624095bff1a15024e9199eee676 (patch)
tree6cc57d085bdd01e493477c870dbe0548137998e1 /agents/webproxyconn.h
parenta24034bdfea259cdc09c74217be75d4f9de0dce5 (diff)
downloadsapd-a45977185a485624095bff1a15024e9199eee676.tar.gz
sapd-a45977185a485624095bff1a15024e9199eee676.zip
reorganize source files into SAP and agents
Diffstat (limited to 'agents/webproxyconn.h')
-rw-r--r--agents/webproxyconn.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/agents/webproxyconn.h b/agents/webproxyconn.h
new file mode 100644
index 0000000..c183462
--- /dev/null
+++ b/agents/webproxyconn.h
@@ -0,0 +1,63 @@
+#ifndef WEBPROXYCONN_H
+#define WEBPROXYCONN_H
+
+#include <QtCore/QObject>
+#include "sapconnection.h"
+#include "sapsocket.h"
+
+class WebProxyTrans;
+
+class WebProxyConn : public QObject
+{
+ Q_OBJECT
+
+public:
+ WebProxyConn(SAPConnection *conn, QObject *parent = 0);
+
+protected:
+ enum MessageType {
+ MessageRequest = 1,
+ MessageResponse = 2,
+ MessageError = 3,
+ MessageAbort = 4
+ };
+
+ struct Message {
+ quint8 command; // Seems to be always 1
+ quint8 subCommand; // Seems to be always 1
+ MessageType type;
+ quint8 transactionId; // Monotonically increasing
+ QByteArray payload;
+ };
+
+ static Message unpackMessage(const QByteArray &data);
+ static QByteArray packMessage(const Message &msg);
+
+ struct RequestHeader {
+ /** Whether this is a CONNECT request, i.e. tunnel. */
+ bool connect;
+ QString host;
+ int port;
+ };
+
+ static RequestHeader parseRequestHeader(const QByteArray &req);
+ static QByteArray removeHeaders(const QByteArray &req);
+
+ void sendMessage(const Message &msg);
+
+ void handleRequest(const Message &msg);
+ void handleAbort(const Message &msg);
+
+private slots:
+ void handleMessageReceived();
+ void handleTransDataReceived(const QByteArray &data);
+ void handleTransDisconnected();
+
+private:
+ SAPConnection *_conn;
+ SAPSocket *_in;
+ SAPSocket *_out;
+ QMap<int, WebProxyTrans*> _trans;
+};
+
+#endif // WEBPROXYCONN_H