Skip to content

Commit ee89151

Browse files
authored
Clean up and fix, changed ssh exit stream command
* Cleaned up some old commented-out code * Commented-out some `lock` and `unlock` calls because they were in the main thread * Removed some global app variables that weren't really being used * (Hopefully) fixed the remote desktop name of connected listening items (the desktop name would go away after a while) * Changed the iffy ssh exit command to use escape characters CRLF + ~. + CRLF
1 parent 78fbb8b commit ee89151

File tree

5 files changed

+48
-83
lines changed

5 files changed

+48
-83
lines changed

src/app.cxx

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ void svConfigWrite ()
601601
ofs << "vncpass=" << base64Encode(reinterpret_cast<const unsigned char *>
602602
(itm->vncPassword.c_str()), itm->vncPassword.size()) << std::endl;
603603
ofs << "type=" << itm->hostType << std::endl;
604-
//ofs << "sshkeypublic=" << itm->sshKeyPublic << std::endl;
605604
ofs << "sshkeyprivate=" << itm->sshKeyPrivate << std::endl;
606605
ofs << "sshuser=" << itm->sshUser << std::endl;
607606
ofs << "sshpass=" << itm->sshPass << std::endl;
@@ -1911,43 +1910,33 @@ void svHandleMainWindowEvents (Fl_Widget * window, void *)
19111910
void svPositionWidgets ()
19121911
{
19131912
// only continue if main window geometry changes
1914-
if (app->mainWin->w() != app->nMainWinPreviousW
1915-
|| app->mainWin->h() != app->nMainWinPreviousH)
1916-
{
1917-
svDebugLog("svPositionWidgets - Resizing GUI elements");
1918-
1919-
// store window geometry for comparison later
1920-
app->nMainWinPreviousW = app->mainWin->w();
1921-
app->nMainWinPreviousH = app->mainWin->h();
1922-
1923-
// resize the host list vertically if the main window resizes
1924-
app->hostList->size(app->hostList->w(), app->mainWin->h() - 26);
1913+
svDebugLog("svPositionWidgets - Resizing GUI elements");
19251914

1926-
// set list buttons position
1927-
app->packButtons->position(3, app->hostList->x() + app->hostList->h() + 3);
1915+
// resize the host list vertically if the main window resizes
1916+
app->hostList->size(app->hostList->w(), app->mainWin->h() - 26);
19281917

1929-
// don't allow host list width to be smaller than right-most button's x+w
1930-
if (app->hostList->w() < (app->packButtons->x() + app->packButtons->w()))
1931-
app->hostList->size((app->packButtons->x() + app->packButtons->w()), app->hostList->h());
1918+
// set list buttons position
1919+
app->packButtons->position(3, app->hostList->x() + app->hostList->h() + 3);
19321920

1933-
// set scroller x
1934-
app->scroller->position(app->hostList->x() + app->hostList->w() + 3, app->scroller->y());
1935-
app->scroller->redraw();
1921+
// don't allow host list width to be smaller than right-most button's x+w
1922+
if (app->hostList->w() < (app->packButtons->x() + app->packButtons->w()))
1923+
app->hostList->size((app->packButtons->x() + app->packButtons->w()), app->hostList->h());
19361924

1937-
VncObject * vnc = app->vncViewer->vnc;
1938-
1939-
// reset scroller position
1940-
if (vnc != NULL)
1941-
{
1942-
svResizeScroller();
1943-
vnc->setObjectVisible();
1944-
}
1925+
// set scroller x
1926+
app->scroller->position(app->hostList->x() + app->hostList->w() + 3, app->scroller->y());
1927+
app->scroller->redraw();
19451928

1946-
Fl::redraw();
1947-
Fl::check();
1929+
VncObject * vnc = app->vncViewer->vnc;
19481930

1949-
return;
1931+
// reset scroller position
1932+
if (vnc != NULL)
1933+
{
1934+
svResizeScroller();
1935+
vnc->setObjectVisible();
19501936
}
1937+
1938+
Fl::redraw();
1939+
Fl::check();
19511940
}
19521941

19531942

@@ -1967,9 +1956,9 @@ void svHandleListItemIconChange (void *)
19671956

19681957
if (itm != NULL && itm->icon != NULL)
19691958
{
1970-
Fl::lock();
1959+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
19711960
app->hostList->icon(i, itm->icon);
1972-
Fl::unlock();
1961+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
19731962
Fl::check();
19741963
}
19751964
}
@@ -1978,7 +1967,7 @@ void svHandleListItemIconChange (void *)
19781967
}
19791968

19801969

1981-
/* handle messages from child threads */
1970+
/* handle connection changes from child threads */
19821971
void svHandleThreadConnection (void * data)
19831972
{
19841973
HostItem * itm = static_cast<HostItem *>(data);
@@ -2026,8 +2015,9 @@ void svHandleThreadConnection (void * data)
20262015

20272016
std::string strHostViewName = "Listening - ";
20282017
strHostViewName.append(vnc->vncClient->desktopName);
2018+
itm->name = strHostViewName;
20292019

2030-
app->hostList->text(nListeningItem, strHostViewName.c_str());
2020+
app->hostList->text(nListeningItem, itm->name.c_str()); // strHostViewName.c_str());
20312021

20322022
// (try to) create another listener
20332023
svDebugLog("svConnectionWatcher - Creating Listener object");
@@ -2126,7 +2116,7 @@ void svHandleThreadCursorChange (void * setToDefault)
21262116
if (vnc == NULL)
21272117
return;
21282118

2129-
Fl::lock();
2119+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
21302120

21312121
// set cursor, if valid
21322122
if (vnc->imgCursor != NULL)
@@ -2136,7 +2126,7 @@ void svHandleThreadCursorChange (void * setToDefault)
21362126
} else
21372127
app->mainWin->cursor(FL_CURSOR_DEFAULT);
21382128

2139-
Fl::unlock();
2129+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
21402130
}
21412131

21422132

@@ -2149,17 +2139,16 @@ void svInsertEmptyItem ()
21492139
itm->hostAddress = "192.168.0.1";
21502140
itm->vncPort = "5900";
21512141
itm->scaling = 'f';
2152-
// itm->sshKeyPublic = "";
21532142
itm->sshKeyPrivate = "";
21542143
itm->showRemoteCursor = true;
21552144
itm->compressLevel = 5;
21562145
itm->qualityLevel = 5;
21572146

2158-
Fl::lock();
2147+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
21592148
app->hostList->add(itm->name.c_str(), itm);
21602149
app->hostList->icon(app->hostList->size(), app->iconDisconnected);
21612150
app->hostList->make_visible(app->hostList->size());
2162-
Fl::unlock();
2151+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
21632152

21642153
Fl::redraw();
21652154
Fl::check();
@@ -2175,7 +2164,7 @@ int svItemNumFromItm (const HostItem * itmIn)
21752164
HostItem * itm = NULL;
21762165
uint16_t nSize = app->hostList->size();
21772166

2178-
Fl::lock();
2167+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
21792168

21802169
// go through hostlist and find item owning matching itmIn
21812170
for (uint16_t i = 0; i <= nSize; i ++)
@@ -2185,13 +2174,13 @@ int svItemNumFromItm (const HostItem * itmIn)
21852174

21862175
if (itm != NULL && itm == itmIn)
21872176
{
2188-
Fl::unlock();
2177+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
21892178

21902179
return i;
21912180
}
21922181
}
21932182

2194-
Fl::unlock();
2183+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
21952184

21962185
return 0;
21972186
}
@@ -2206,7 +2195,7 @@ HostItem * svItmFromVnc (const VncObject * vncIn)
22062195
HostItem * itm = NULL;
22072196
uint16_t nSize = app->hostList->size();
22082197

2209-
Fl::lock();
2198+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
22102199

22112200
for (uint16_t i = 0; i <= nSize; i ++)
22122201
{
@@ -2217,14 +2206,14 @@ HostItem * svItmFromVnc (const VncObject * vncIn)
22172206
{
22182207
if (itm->vnc == vncIn)
22192208
{
2220-
Fl::unlock();
2209+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
22212210

22222211
return itm;
22232212
}
22242213
}
22252214
}
22262215

2227-
Fl::unlock();
2216+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
22282217

22292218
return NULL;
22302219
}
@@ -2928,7 +2917,6 @@ void svShowItemOptions (HostItem * im)
29282917
itm->vncPort = "5900";
29292918
itm->sshPort = "";
29302919
itm->scaling = 's';
2931-
// itm->sshKeyPublic = "";
29322920
itm->sshKeyPrivate = "";
29332921
itm->showRemoteCursor = true;
29342922
itm->compressLevel = 5;

src/app.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class AppVars
113113
itmBeingEdited(NULL),
114114
scanIsRunning(false),
115115
nCurrentScanItem(0),
116-
nMainWinPreviousW(0),
117-
nMainWinPreviousH(0),
118116
nScanTimeout(2),
119117
nDeadTimeout(100),
120118
nStartingLocalPort(15000),
@@ -152,12 +150,12 @@ class AppVars
152150
std::cout << "SpiritVNC - FLTK: CRITICAL - Could not get user's login name"
153151
" from environment\n\nExiting\n";
154152

155-
Fl::lock();
153+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
156154
fl_message_hotspot(0);
157155
fl_message_title("SpiritVNC - FLTK");
158156
fl_message("%s", "CRITICAL ERROR - Could not get user's login name"
159157
" from environment\n\nExiting\n");
160-
Fl::unlock();
158+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
161159
exit(1);
162160
}
163161

@@ -210,8 +208,6 @@ class AppVars
210208
HostItem * itmBeingEdited;
211209
bool scanIsRunning;
212210
int nCurrentScanItem;
213-
int nMainWinPreviousW;
214-
int nMainWinPreviousH;
215211
int nScanTimeout;
216212
int nDeadTimeout;
217213
int nStartingLocalPort;
@@ -281,7 +277,7 @@ void svHandleHostListButtons (Fl_Widget *, void *);
281277
void svHandleHostListEvents (Fl_Widget *, void *);
282278
void svHandleMainWindowEvents (Fl_Widget *, void *);
283279
void svPositionWidgets ();
284-
void svHandleListItemIconChange (void * notUsed);
280+
void svHandleListItemIconChange (void *);
285281
void svHandleThreadConnection (void *);
286282
void svHandleThreadCursorChange (void *);
287283
void svInsertEmptyItem ();

src/hostitem.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,13 @@ class HostItem
5555
sshPort(""),
5656
sshUser(""),
5757
sshPass(""),
58-
// sshKeyPublic(""),
5958
sshKeyPrivate(""),
6059
sshLocalPort(0),
6160
vncPassword(""),
6261
hostType('v'),
6362
vnc(NULL),
6463
threadRFB(0),
6564
threadRFBRunning(false),
66-
//threadSSH(0),
67-
//threadLoop(0),
6865
sshReady(false),
6966
vncAddressAndPort(""),
7067
f12Macro(""),
@@ -98,16 +95,13 @@ class HostItem
9895
std::string sshPort;
9996
std::string sshUser;
10097
std::string sshPass;
101-
// std::string sshKeyPublic;
10298
std::string sshKeyPrivate;
10399
int sshLocalPort;
104100
std::string vncPassword;
105101
char hostType;
106102
VncObject * vnc;
107103
pthread_t threadRFB;
108104
bool threadRFBRunning;
109-
//pthread_t threadSSH;
110-
//pthread_t threadLoop;
111105
bool sshReady;
112106
std::string vncAddressAndPort;
113107
std::string f12Macro;

src/ssh.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838

3939
/* attempts to close the popen'd ssh process */
40+
/* (run as thread) */
4041
void * svSSHCloseHelper (void * itmData)
4142
{
4243
// detach this thread
@@ -47,9 +48,15 @@ void * svSSHCloseHelper (void * itmData)
4748
if (itm == NULL || itm->sshCmdStream == NULL)
4849
return SV_RET_VOID;
4950

50-
fprintf(itm->sshCmdStream, "%s\r\n", "exit");
51+
// fprintf(itm->sshCmdStream, "%s\r\n", "exit"); // <<--- trying different way to close (below) ---<<<
52+
53+
// send 'exit' control-char sequence
54+
fprintf(itm->sshCmdStream, "\r\n%s", "~.");
5155
fflush(itm->sshCmdStream);
56+
// send extra CRLF, just for fun
57+
fprintf(itm->sshCmdStream, "\r\n");
5258

59+
// close the ssh process command stream
5360
pclose(itm->sshCmdStream);
5461

5562
return SV_RET_VOID;

src/vnc.cxx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,8 @@ void VncObject::createVNCObject (HostItem * itm)
184184
svDebugLog("svCreateVNCObject - Creating and running threadSSH");
185185

186186
// create, launch and detach call to create our ssh connection
187-
//int sshResult = pthread_create(&itm->threadSSH, NULL, svCreateSSHConnection, itm);
188187
svCreateSSHConnection(itm);
189188

190-
////if (sshResult != 0)
191-
//// ### THIS BLOCK COMMENTED OUT 2022-08-05 ###
192-
//if (itm->sshReady == false)
193-
//{
194-
//svLogToFile("ERROR - Couldn't create SSH thread for '" + itm->name +
195-
//"' - " + itm->hostAddress);
196-
//itm->isConnecting = false;
197-
//itm->hasCouldntConnect = true;
198-
//itm->hasError = true;
199-
//itm->lastErrorMessage = "Unable to make SSH connection";
200-
201-
////if (vnc != NULL && vnc->vncClient != NULL)
202-
//VncObject::endAndDeleteViewer(&vnc);
203-
204-
//svHandleThreadConnection(itm);
205-
206-
//return;
207-
//}
208-
209189
time_t sshDelay = time(NULL) + itm->sshWaitTime;
210190

211191
svDebugLog("svCreateVNCObject - About to enter itm->sshReady timer loop");
@@ -722,9 +702,9 @@ void VncObject::masterMessageLoop ()
722702
// for (uint16_t i = 0; i <= app->hostList->size(); i ++)
723703
for (uint16_t i = 0; i <= nSize; i ++)
724704
{
725-
Fl::lock();
705+
// Fl::lock(); // <<<--- commenting out because this is main thread ---<<<
726706
itm = static_cast<HostItem *>(app->hostList->data(i));
727-
Fl::unlock();
707+
// Fl::unlock(); // <<<--- commenting out because this is main thread ---<<<
728708

729709
if (itm == NULL)
730710
continue;

0 commit comments

Comments
 (0)