aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon/proxywidget.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-05-17 04:18:13 +0000
committerMike Buland <eichlan@xagasoft.com>2011-05-17 04:18:13 +0000
commit6aefa6632023c99c5b91bae0e099df94fa69d890 (patch)
tree6ac83b347cc70dca827c887f0046924dabec042d /src/gatscon/proxywidget.cpp
parentefcbdb7a0347b4399cbabacf3cbea432eeafb17b (diff)
downloadlibgats-6aefa6632023c99c5b91bae0e099df94fa69d890.tar.gz
libgats-6aefa6632023c99c5b91bae0e099df94fa69d890.tar.bz2
libgats-6aefa6632023c99c5b91bae0e099df94fa69d890.tar.xz
libgats-6aefa6632023c99c5b91bae0e099df94fa69d890.zip
GatsCon now supports proxying, and way better than qtbenc ever did. Not only
does it proxy, but you can inject your own messages going to the client or host. Pretty slick, really. Next up, reading and creating files.
Diffstat (limited to 'src/gatscon/proxywidget.cpp')
-rw-r--r--src/gatscon/proxywidget.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/gatscon/proxywidget.cpp b/src/gatscon/proxywidget.cpp
new file mode 100644
index 0000000..28bd1fc
--- /dev/null
+++ b/src/gatscon/proxywidget.cpp
@@ -0,0 +1,115 @@
1#include "proxywidget.h"
2#include "proxythread.h"
3
4#include "gatstotree.h"
5
6#include <QMessageBox>
7
8#include <gats/types.h>
9#include <bu/sio.h>
10
11using namespace Bu;
12
13ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn,
14 const QByteArray baHost, int iPortOut ) :
15 QWidget( pParent ),
16 pPrx( NULL )
17{
18 setupUi( this );
19
20 pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut );
21
22 connect( pPrx, SIGNAL(gotConnection()),
23 this, SLOT(gotConnection()), Qt::QueuedConnection );
24 connect( pPrx, SIGNAL(recv( Gats::Object *)),
25 this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection );
26 connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)),
27 this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection );
28
29 pPrx->start();
30}
31
32ProxyWidget::~ProxyWidget()
33{
34}
35
36void ProxyWidget::sendToClient()
37{
38 try
39 {
40 Gats::Object *pObj = Gats::Object::strToGats(
41 leGats->text().toAscii().constData()
42 );
43 sio << "Send: " << *pObj << sio.nl;
44 QTreeWidgetItem *pIt = new QTreeWidgetItem(
45 twHistory->invisibleRootItem()
46 );
47 pIt->setText( 0, "proxy -> client" );
48 gatsToTree( pIt, pObj );
49 pPrx->send( pObj );
50 delete pObj;
51
52 leGats->setText("");
53 leGats->setFocus();
54 }
55 catch( Bu::ExceptionBase &e )
56 {
57 QMessageBox::critical( this, "GatsCon - Error", e.what() );
58 }
59}
60
61void ProxyWidget::sendToServer()
62{
63 try
64 {
65 Gats::Object *pObj = Gats::Object::strToGats(
66 leGats->text().toAscii().constData()
67 );
68 sio << "Send: " << *pObj << sio.nl;
69 QTreeWidgetItem *pIt = new QTreeWidgetItem(
70 twHistory->invisibleRootItem()
71 );
72 pIt->setText( 0, "proxy -> host" );
73 gatsToTree( pIt, pObj );
74 pPrx->pHost->send( pObj );
75 delete pObj;
76
77 leGats->setText("");
78 leGats->setFocus();
79 }
80 catch( Bu::ExceptionBase &e )
81 {
82 QMessageBox::critical( this, "GatsCon - Error", e.what() );
83 }
84}
85
86void ProxyWidget::clientRecv( Gats::Object *pObj )
87{
88 sio << "Recv: " << *pObj << sio.nl;
89
90 QTreeWidgetItem *pIt = new QTreeWidgetItem(
91 twHistory->invisibleRootItem()
92 );
93 pIt->setText( 0, "client -> host" );
94 gatsToTree( pIt, pObj );
95 delete pObj;
96}
97
98void ProxyWidget::hostRecv( Gats::Object *pObj )
99{
100 sio << "Recv: " << *pObj << sio.nl;
101
102 QTreeWidgetItem *pIt = new QTreeWidgetItem(
103 twHistory->invisibleRootItem()
104 );
105 pIt->setText( 0, "host -> client" );
106 gatsToTree( pIt, pObj );
107 delete pObj;
108}
109
110void ProxyWidget::gotConnection()
111{
112 lwConnect->stop();
113 swRoot->setCurrentIndex( 1 );
114}
115