aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gatscon/clientthread.cpp2
-rw-r--r--src/gatscon/clientwidget.cpp17
-rw-r--r--src/gatscon/clientwidget.h2
-rw-r--r--src/gatscon/mainwnd.cpp25
-rw-r--r--src/gatscon/proxythread.cpp108
-rw-r--r--src/gatscon/proxythread.h60
-rw-r--r--src/gatscon/proxywidget.cpp115
-rw-r--r--src/gatscon/proxywidget.h30
-rw-r--r--src/gatscon/proxywidget.ui181
-rw-r--r--src/gatscon/setupproxydlg.cpp27
-rw-r--r--src/gatscon/setupproxydlg.h18
-rw-r--r--src/gatscon/setupproxydlg.ui112
12 files changed, 682 insertions, 15 deletions
diff --git a/src/gatscon/clientthread.cpp b/src/gatscon/clientthread.cpp
index b1dc4d0..4c7b72a 100644
--- a/src/gatscon/clientthread.cpp
+++ b/src/gatscon/clientthread.cpp
@@ -30,7 +30,7 @@ void ClientThread::run()
30 { 30 {
31 Gats::Object *pObj = gsCli.readObject(); 31 Gats::Object *pObj = gsCli.readObject();
32 if( pObj == NULL ) 32 if( pObj == NULL )
33 break; 33 continue;
34 34
35 emit recv( pObj ); 35 emit recv( pObj );
36 } 36 }
diff --git a/src/gatscon/clientwidget.cpp b/src/gatscon/clientwidget.cpp
index 6039035..0ea04a3 100644
--- a/src/gatscon/clientwidget.cpp
+++ b/src/gatscon/clientwidget.cpp
@@ -1,5 +1,4 @@
1#include "clientwidget.h" 1#include "clientwidget.h"
2#include "connectdlg.h"
3#include "clientthread.h" 2#include "clientthread.h"
4 3
5#include "gatstotree.h" 4#include "gatstotree.h"
@@ -11,23 +10,17 @@
11 10
12using namespace Bu; 11using namespace Bu;
13 12
14ClientWidget::ClientWidget( QWidget *pParent ) : 13ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost,
14 int iPort ) :
15 QWidget( pParent ) 15 QWidget( pParent )
16{ 16{
17 setupUi( this ); 17 setupUi( this );
18 18
19 { 19 pCli = new ClientThread( this, baHost, iPort );
20 ConnectDlg dlg( this );
21 dlg.exec();
22
23 sio << "Connect: " << dlg.getHostname().constData() << ":"
24 << dlg.getPort() << sio.nl;
25
26 pCli = new ClientThread( this, dlg.getHostname(), dlg.getPort() );
27 }
28 pCli->start();
29 connect( pCli, SIGNAL(recv( Gats::Object *)), 20 connect( pCli, SIGNAL(recv( Gats::Object *)),
30 this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); 21 this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection );
22
23 pCli->start();
31} 24}
32 25
33ClientWidget::~ClientWidget() 26ClientWidget::~ClientWidget()
diff --git a/src/gatscon/clientwidget.h b/src/gatscon/clientwidget.h
index 21fb1b7..9ce2798 100644
--- a/src/gatscon/clientwidget.h
+++ b/src/gatscon/clientwidget.h
@@ -12,7 +12,7 @@ class ClientWidget : public QWidget, protected Ui::ClientWidget
12{ 12{
13 Q_OBJECT; 13 Q_OBJECT;
14public: 14public:
15 ClientWidget( QWidget *pParent=NULL ); 15 ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort );
16 virtual ~ClientWidget(); 16 virtual ~ClientWidget();
17 17
18public slots: 18public slots:
diff --git a/src/gatscon/mainwnd.cpp b/src/gatscon/mainwnd.cpp
index c86e1c2..f20a531 100644
--- a/src/gatscon/mainwnd.cpp
+++ b/src/gatscon/mainwnd.cpp
@@ -1,5 +1,10 @@
1#include "mainwnd.h" 1#include "mainwnd.h"
2
2#include "clientwidget.h" 3#include "clientwidget.h"
4#include "proxywidget.h"
5
6#include "connectdlg.h"
7#include "setupproxydlg.h"
3 8
4MainWnd::MainWnd() 9MainWnd::MainWnd()
5{ 10{
@@ -12,11 +17,29 @@ MainWnd::~MainWnd()
12 17
13void MainWnd::connect() 18void MainWnd::connect()
14{ 19{
15 setCentralWidget( new ClientWidget( this ) ); 20 ConnectDlg dlg( this );
21 if( dlg.exec() == QDialog::Accepted )
22 {
23 setCentralWidget(
24 new ClientWidget(
25 this, dlg.getHostname(), dlg.getPort()
26 )
27 );
28 }
16} 29}
17 30
18void MainWnd::proxy() 31void MainWnd::proxy()
19{ 32{
33 SetupProxyDlg dlg( this );
34
35 if( dlg.exec() == QDialog::Accepted )
36 {
37 setCentralWidget(
38 new ProxyWidget(
39 this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut()
40 )
41 );
42 }
20} 43}
21 44
22void MainWnd::open() 45void MainWnd::open()
diff --git a/src/gatscon/proxythread.cpp b/src/gatscon/proxythread.cpp
new file mode 100644
index 0000000..574b56b
--- /dev/null
+++ b/src/gatscon/proxythread.cpp
@@ -0,0 +1,108 @@
1#include "proxythread.h"
2
3#include <gats/types.h>
4
5#include <bu/tcpsocket.h>
6#include <bu/tcpserversocket.h>
7#include <bu/sio.h>
8#include <bu/membuf.h>
9
10using namespace Bu;
11
12ProxyThread::ProxyThread( QObject *pParent, int iPortIn,
13 const QByteArray &baHostOut, int iPortOut ) :
14 QThread( pParent ),
15 pHost( NULL ),
16 iPortIn( iPortIn ),
17 baHostOut( baHostOut ),
18 iPortOut( iPortOut ),
19 gsCli( ssCli )
20{
21 pHost = new ProxyHostThread( pParent, this );
22}
23
24ProxyThread::~ProxyThread()
25{
26}
27
28void ProxyThread::send( Gats::Object *pObj )
29{
30 MemBuf bg;
31 Gats::GatsStream gs( bg );
32 gs.writeObject( pObj );
33 ssCli.write( bg.getString().getStr(), bg.getString().getSize() );
34}
35
36void ProxyThread::run()
37{
38 int iSockIn;
39
40 {
41 TcpServerSocket tsIn( iPortIn );
42 do
43 {
44 iSockIn = tsIn.accept( 5 );
45 } while( iSockIn < 0 );
46 }
47
48 emit gotConnection();
49
50 ssCli.setStream( new TcpSocket( iSockIn ) );
51 ssCli.setBlocking( true );
52
53 pHost->setStream(
54 new TcpSocket( baHostOut.constData(), iPortOut )
55 );
56
57 pHost->start();
58
59 while( !ssCli.isEos() )
60 {
61 Gats::Object *pObj = gsCli.readObject();
62 if( pObj == NULL )
63 continue;
64
65 pHost->send( pObj );
66 emit recv( pObj );
67 }
68
69}
70
71ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) :
72 QThread( pParent ),
73 pClient( pClient ),
74 ssHst(),
75 gsHst( ssHst )
76{
77}
78
79ProxyHostThread::~ProxyHostThread()
80{
81}
82
83void ProxyHostThread::send( Gats::Object *pObj )
84{
85 MemBuf bg;
86 Gats::GatsStream gs( bg );
87 gs.writeObject( pObj );
88 ssHst.write( bg.getString().getStr(), bg.getString().getSize() );
89}
90
91void ProxyHostThread::setStream( Bu::Stream *pStr )
92{
93 ssHst.setStream( pStr );
94}
95
96void ProxyHostThread::run()
97{
98 while( !ssHst.isEos() )
99 {
100 Gats::Object *pObj = gsHst.readObject();
101 if( pObj == NULL )
102 continue;
103
104 pClient->send( pObj );
105 emit recv( pObj );
106 }
107}
108
diff --git a/src/gatscon/proxythread.h b/src/gatscon/proxythread.h
new file mode 100644
index 0000000..df75046
--- /dev/null
+++ b/src/gatscon/proxythread.h
@@ -0,0 +1,60 @@
1#ifndef PROXY_THREAD_H
2#define PROXY_THREAD_H
3
4#include <QThread>
5
6#include <bu/streamstack.h>
7#include <gats/gatsstream.h>
8
9class ProxyThread : public QThread
10{
11 Q_OBJECT;
12public:
13 ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut,
14 int iPortOut );
15 virtual ~ProxyThread();
16
17 class ProxyHostThread *pHost;
18
19 void send( Gats::Object *pObj );
20
21signals:
22 void recv( Gats::Object *pObj );
23 void gotConnection();
24
25protected:
26 virtual void run();
27
28private:
29 int iPortIn;
30 QByteArray baHostOut;
31 int iPortOut;
32
33 Bu::StreamStack ssCli;
34 Gats::GatsStream gsCli;
35};
36
37class ProxyHostThread : public QThread
38{
39 Q_OBJECT;
40public:
41 ProxyHostThread( QObject *pParent, ProxyThread *pClient );
42 virtual ~ProxyHostThread();
43
44 void send( Gats::Object *pObj );
45
46 void setStream( Bu::Stream *pStr );
47
48signals:
49 void recv( Gats::Object *pObj );
50
51protected:
52 virtual void run();
53
54private:
55 ProxyThread *pClient;
56 Bu::StreamStack ssHst;
57 Gats::GatsStream gsHst;
58};
59
60#endif
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
diff --git a/src/gatscon/proxywidget.h b/src/gatscon/proxywidget.h
new file mode 100644
index 0000000..0ef1fd4
--- /dev/null
+++ b/src/gatscon/proxywidget.h
@@ -0,0 +1,30 @@
1#ifndef PROXY_WIDGET_H
2#define PROXY_WIDGET_H
3
4#include "ui_proxywidget.h"
5
6namespace Gats
7{
8 class Object;
9};
10
11class ProxyWidget : public QWidget, protected Ui::ProxyWidget
12{
13 Q_OBJECT;
14public:
15 ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost,
16 int iPortOut );
17 virtual ~ProxyWidget();
18
19public slots:
20 void sendToClient();
21 void sendToServer();
22 void clientRecv( Gats::Object *pObj );
23 void hostRecv( Gats::Object *pObj );
24 void gotConnection();
25
26private:
27 class ProxyThread *pPrx;
28};
29
30#endif
diff --git a/src/gatscon/proxywidget.ui b/src/gatscon/proxywidget.ui
new file mode 100644
index 0000000..995fc73
--- /dev/null
+++ b/src/gatscon/proxywidget.ui
@@ -0,0 +1,181 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>ProxyWidget</class>
4 <widget class="QWidget" name="ProxyWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>338</width>
10 <height>300</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Form</string>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout_2">
17 <property name="margin">
18 <number>0</number>
19 </property>
20 <item>
21 <widget class="QStackedWidget" name="swRoot">
22 <property name="currentIndex">
23 <number>0</number>
24 </property>
25 <widget class="QWidget" name="page">
26 <layout class="QVBoxLayout" name="verticalLayout_4">
27 <item>
28 <spacer name="verticalSpacer">
29 <property name="orientation">
30 <enum>Qt::Vertical</enum>
31 </property>
32 <property name="sizeHint" stdset="0">
33 <size>
34 <width>20</width>
35 <height>40</height>
36 </size>
37 </property>
38 </spacer>
39 </item>
40 <item>
41 <widget class="QLabel" name="label_2">
42 <property name="text">
43 <string>Listening for connections...</string>
44 </property>
45 <property name="alignment">
46 <set>Qt::AlignCenter</set>
47 </property>
48 </widget>
49 </item>
50 <item>
51 <widget class="LoadingWidget" name="lwConnect" native="true">
52 <property name="minimumSize">
53 <size>
54 <width>0</width>
55 <height>50</height>
56 </size>
57 </property>
58 </widget>
59 </item>
60 <item>
61 <spacer name="verticalSpacer_2">
62 <property name="orientation">
63 <enum>Qt::Vertical</enum>
64 </property>
65 <property name="sizeHint" stdset="0">
66 <size>
67 <width>20</width>
68 <height>40</height>
69 </size>
70 </property>
71 </spacer>
72 </item>
73 </layout>
74 </widget>
75 <widget class="QWidget" name="page_2">
76 <layout class="QVBoxLayout" name="verticalLayout_3">
77 <item>
78 <widget class="QTreeWidget" name="twHistory">
79 <column>
80 <property name="text">
81 <string>Name</string>
82 </property>
83 </column>
84 <column>
85 <property name="text">
86 <string>Type</string>
87 </property>
88 </column>
89 <column>
90 <property name="text">
91 <string>Value</string>
92 </property>
93 </column>
94 </widget>
95 </item>
96 <item>
97 <layout class="QHBoxLayout" name="horizontalLayout">
98 <item>
99 <widget class="QLabel" name="label">
100 <property name="text">
101 <string>Gats:</string>
102 </property>
103 </widget>
104 </item>
105 <item>
106 <widget class="QLineEdit" name="leGats"/>
107 </item>
108 <item>
109 <layout class="QVBoxLayout" name="verticalLayout">
110 <item>
111 <widget class="QPushButton" name="pushButton">
112 <property name="text">
113 <string>Send to Client</string>
114 </property>
115 </widget>
116 </item>
117 <item>
118 <widget class="QPushButton" name="pushButton_2">
119 <property name="text">
120 <string>Send to Server</string>
121 </property>
122 </widget>
123 </item>
124 </layout>
125 </item>
126 </layout>
127 </item>
128 </layout>
129 </widget>
130 </widget>
131 </item>
132 </layout>
133 </widget>
134 <customwidgets>
135 <customwidget>
136 <class>LoadingWidget</class>
137 <extends>QWidget</extends>
138 <header>loadingwidget.h</header>
139 <container>1</container>
140 </customwidget>
141 </customwidgets>
142 <resources/>
143 <connections>
144 <connection>
145 <sender>pushButton</sender>
146 <signal>clicked()</signal>
147 <receiver>ProxyWidget</receiver>
148 <slot>sendToClient()</slot>
149 <hints>
150 <hint type="sourcelabel">
151 <x>280</x>
152 <y>258</y>
153 </hint>
154 <hint type="destinationlabel">
155 <x>392</x>
156 <y>223</y>
157 </hint>
158 </hints>
159 </connection>
160 <connection>
161 <sender>pushButton_2</sender>
162 <signal>clicked()</signal>
163 <receiver>ProxyWidget</receiver>
164 <slot>sendToServer()</slot>
165 <hints>
166 <hint type="sourcelabel">
167 <x>306</x>
168 <y>284</y>
169 </hint>
170 <hint type="destinationlabel">
171 <x>199</x>
172 <y>340</y>
173 </hint>
174 </hints>
175 </connection>
176 </connections>
177 <slots>
178 <slot>sendToClient()</slot>
179 <slot>sendToServer()</slot>
180 </slots>
181</ui>
diff --git a/src/gatscon/setupproxydlg.cpp b/src/gatscon/setupproxydlg.cpp
new file mode 100644
index 0000000..7c7a873
--- /dev/null
+++ b/src/gatscon/setupproxydlg.cpp
@@ -0,0 +1,27 @@
1#include "setupproxydlg.h"
2
3SetupProxyDlg::SetupProxyDlg( QWidget *pParent ) :
4 QDialog( pParent )
5{
6 setupUi( this );
7}
8
9SetupProxyDlg::~SetupProxyDlg()
10{
11}
12
13int SetupProxyDlg::getPortIn() const
14{
15 return sbPortIn->value();
16}
17
18QByteArray SetupProxyDlg::getHostOut() const
19{
20 return leHostOut->text().toAscii();
21}
22
23int SetupProxyDlg::getPortOut() const
24{
25 return sbPortOut->value();
26}
27
diff --git a/src/gatscon/setupproxydlg.h b/src/gatscon/setupproxydlg.h
new file mode 100644
index 0000000..6cc31bd
--- /dev/null
+++ b/src/gatscon/setupproxydlg.h
@@ -0,0 +1,18 @@
1#ifndef SETUP_PROXY_DLG_H
2#define SETUP_PROXY_DLG_H
3
4#include "ui_setupproxydlg.h"
5
6class SetupProxyDlg : public QDialog, protected Ui::SetupProxyDlg
7{
8 Q_OBJECT;
9public:
10 SetupProxyDlg( QWidget *pParent=NULL );
11 virtual ~SetupProxyDlg();
12
13 int getPortIn() const;
14 QByteArray getHostOut() const;
15 int getPortOut() const;
16};
17
18#endif
diff --git a/src/gatscon/setupproxydlg.ui b/src/gatscon/setupproxydlg.ui
new file mode 100644
index 0000000..8482193
--- /dev/null
+++ b/src/gatscon/setupproxydlg.ui
@@ -0,0 +1,112 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>SetupProxyDlg</class>
4 <widget class="QDialog" name="SetupProxyDlg">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>359</width>
10 <height>122</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>GatsCon - Setup Proxy</string>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <item>
18 <layout class="QFormLayout" name="formLayout">
19 <item row="0" column="0">
20 <widget class="QLabel" name="label_2">
21 <property name="text">
22 <string>Listening port:</string>
23 </property>
24 </widget>
25 </item>
26 <item row="0" column="1">
27 <widget class="QSpinBox" name="sbPortIn">
28 <property name="minimum">
29 <number>1</number>
30 </property>
31 <property name="maximum">
32 <number>32767</number>
33 </property>
34 </widget>
35 </item>
36 <item row="1" column="0">
37 <widget class="QLabel" name="label_3">
38 <property name="text">
39 <string>Target host:</string>
40 </property>
41 </widget>
42 </item>
43 <item row="1" column="1">
44 <widget class="QLineEdit" name="leHostOut"/>
45 </item>
46 <item row="2" column="0">
47 <widget class="QLabel" name="label_4">
48 <property name="text">
49 <string>Target port:</string>
50 </property>
51 </widget>
52 </item>
53 <item row="2" column="1">
54 <widget class="QSpinBox" name="sbPortOut">
55 <property name="minimum">
56 <number>1</number>
57 </property>
58 <property name="maximum">
59 <number>32767</number>
60 </property>
61 </widget>
62 </item>
63 </layout>
64 </item>
65 <item>
66 <widget class="QDialogButtonBox" name="buttonBox">
67 <property name="orientation">
68 <enum>Qt::Horizontal</enum>
69 </property>
70 <property name="standardButtons">
71 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
72 </property>
73 </widget>
74 </item>
75 </layout>
76 </widget>
77 <resources/>
78 <connections>
79 <connection>
80 <sender>buttonBox</sender>
81 <signal>accepted()</signal>
82 <receiver>SetupProxyDlg</receiver>
83 <slot>accept()</slot>
84 <hints>
85 <hint type="sourcelabel">
86 <x>248</x>
87 <y>254</y>
88 </hint>
89 <hint type="destinationlabel">
90 <x>157</x>
91 <y>274</y>
92 </hint>
93 </hints>
94 </connection>
95 <connection>
96 <sender>buttonBox</sender>
97 <signal>rejected()</signal>
98 <receiver>SetupProxyDlg</receiver>
99 <slot>reject()</slot>
100 <hints>
101 <hint type="sourcelabel">
102 <x>316</x>
103 <y>260</y>
104 </hint>
105 <hint type="destinationlabel">
106 <x>286</x>
107 <y>274</y>
108 </hint>
109 </hints>
110 </connection>
111 </connections>
112</ui>