Skip to content

Commit e11695f

Browse files
authored
Version bump, listen fix, cppcheck
* Bumped version to 0.6.4 * Implement fixes suggested by cppcheck * Fix long-time listener bug where an invalid reverse connection would trash program's ability to spawn a new listener * Free some strdups * Move timestamp generation (for logs, stdout messages) to its own function to reduce repetitive code * Minor code cleanup and formatting
1 parent 4eda34d commit e11695f

File tree

8 files changed

+272
-355
lines changed

8 files changed

+272
-355
lines changed

src/app.cxx

Lines changed: 170 additions & 235 deletions
Large diffs are not rendered by default.

src/app.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#ifndef APP_H
3636
#define APP_H
3737

38+
/* === windows only === */
3839
#ifdef _WIN32
3940
#include <winsock2.h>
4041
#include <windows.h>
@@ -55,17 +56,20 @@
5556
#include <FL/Fl_Input.H>
5657
#include <FL/Fl_Menu_Item.H>
5758
#include <FL/Fl_Pack.H>
59+
#include <FL/Fl_PNG_Image.H>
5860
#include <FL/Fl_Radio_Round_Button.H>
5961
#include <FL/Fl_Scroll.H>
6062
#include <FL/Fl_Secret_Input.H>
6163
#include <FL/Fl_Spinner.H>
64+
#include <FL/Fl_Tabs.H>
6265
#include <FL/Fl_Tooltip.H>
6366
#include <FL/Fl_Multiline_Output.H>
6467
#include <FL/Fl_Widget.H>
6568
#include <FL/Fl_Window.H>
6669

6770
#include <fstream>
6871

72+
/* === *nix-like only == */
6973
#ifndef _WIN32
7074
#include <arpa/inet.h>
7175
#include <netinet/in.h>
@@ -78,7 +82,6 @@
7882
#include <sys/types.h>
7983
#include <stdlib.h>
8084
#include <signal.h>
81-
#include <vector>
8285

8386
#include "base64.h"
8487
#include "consts_enums.h"
@@ -109,7 +112,7 @@ class AppVars
109112
iconConnected(NULL),
110113
iconNoConnect(NULL),
111114
iconConnecting(NULL),
112-
libVncVncPointer((void *)"VncObject"),
115+
libVncVncPointer(strdup("VncObject")),
113116
configPath(""),
114117
configPathAndFile(""),
115118
requestedListWidth(170),
@@ -130,7 +133,6 @@ class AppVars
130133
scanIsRunning(false),
131134
nCurrentScanItem(0),
132135
nScanTimeout(2),
133-
//nDeadTimeout(100),
134136
nStartingLocalPort(15000),
135137
showTooltips(true),
136138
enableLogToFile(false),
@@ -199,17 +201,17 @@ class AppVars
199201

200202
// set up config file path and file
201203

202-
// for macOS / OS X
204+
// === macOS / OS X ===
203205
#if defined __APPLE__
204206
configPath = "/Users/" + userName + "/.spiritvnc/";
205-
// Windows 10+
207+
// === Windows 10+ ===
206208
#elif defined _WIN32
207209
configPath = std::string(getenv("APPDATA")) + "\\SpiritVNC\\";
210+
// === solaris or openindiana ===
208211
#elif defined __sun__
209-
// for solaris or openindiana
210212
configPath = "/export/home/" + userName + "/.spiritvnc/";
213+
// === default linux, freebsd, others ===
211214
#else
212-
// default is typical linux, freebsd path
213215
configPath = "/home/" + userName + "/.spiritvnc/";
214216
#endif
215217

@@ -249,7 +251,6 @@ class AppVars
249251
bool scanIsRunning;
250252
int nCurrentScanItem;
251253
uint16_t nScanTimeout;
252-
//uint16_t nDeadTimeout;
253254
int nStartingLocalPort;
254255
bool showTooltips;
255256
bool enableLogToFile;
@@ -286,7 +287,6 @@ class SVInput : public Fl_Input
286287
public:
287288
SVInput (int x, int y, int w, int h, const char * label = 0) :
288289
Fl_Input(x, y, w, h, label) {}
289-
//private:
290290
int handle (int event);
291291
};
292292

@@ -369,6 +369,7 @@ void svItmOptionsRadioButtonsCallback (Fl_Widget *, void *);
369369
void svListeningModeBegin ();
370370
void svListeningModeEnd ();
371371
void svLogToFile (const std::string&);
372+
std::string svMakeTimeStamp (bool dashSeps = true);
372373
void svMessageWindow (const std::string&, const std::string& = "SpiritVNC");
373374
bool svThereAreConnectedItems ();
374375
void svPopUpEditMenu (Fl_Input_ *);

src/base64.cxx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
#include "base64.h"
3636

3737

38-
/* base64 */
38+
/* base64 */
3939
static inline bool base64Type (unsigned char c)
4040
{
4141
return (isalnum(c) || (c == '+') || (c == '/'));
4242
}
4343

4444

45-
/* base64 */
45+
/* base64 */
4646
std::string base64Decode (std::string const& encoded_string)
4747
{
4848
size_t in_len = encoded_string.size();
@@ -54,18 +54,18 @@ std::string base64Decode (std::string const& encoded_string)
5454

5555
while (in_len-- && ( encoded_string[in_] != '=') && base64Type(encoded_string[in_]))
5656
{
57-
char_array_4[i++] = encoded_string[in_]; in_++;
57+
char_array_4[i ++] = encoded_string[in_]; in_ ++;
5858

5959
if (i ==4)
6060
{
61-
for (i = 0; i < 4; i++)
61+
for (i = 0; i < 4; i ++)
6262
char_array_4[i] = static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
6363

6464
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
6565
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
6666
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
6767

68-
for (i = 0; (i < 3); i++)
68+
for (i = 0; (i < 3); i ++)
6969
ret += char_array_3[i];
7070

7171
i = 0;
@@ -74,25 +74,25 @@ std::string base64Decode (std::string const& encoded_string)
7474

7575
if (i != 0)
7676
{
77-
for (int j = i; j <4; j++)
77+
for (int j = i; j <4; j ++)
7878
char_array_4[j] = 0;
7979

80-
for (int j = 0; j <4; j++)
80+
for (int j = 0; j <4; j ++)
8181
char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
8282

8383
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
8484
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
8585
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
8686

87-
for (size_t j = 0; (j < i - 1); j++)
87+
for (size_t j = 0; (j < i - 1); j ++)
8888
ret += char_array_3[j];
8989
}
9090

9191
return ret;
9292
}
9393

9494

95-
/* base64 */
95+
/* base64 */
9696
std::string base64Encode (unsigned char const * bytes_to_encode, unsigned int in_len)
9797
{
9898
std::string ret;
@@ -103,7 +103,7 @@ std::string base64Encode (unsigned char const * bytes_to_encode, unsigned int in
103103

104104
while (in_len--)
105105
{
106-
char_array_3[i++] = *(bytes_to_encode++);
106+
char_array_3[i ++] = *(bytes_to_encode ++);
107107

108108
if (i == 3)
109109
{
@@ -112,7 +112,7 @@ std::string base64Encode (unsigned char const * bytes_to_encode, unsigned int in
112112
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
113113
char_array_4[3] = char_array_3[2] & 0x3f;
114114

115-
for (i = 0; (i < 4) ; i++)
115+
for (i = 0; (i < 4) ; i ++)
116116
ret += base64_chars[char_array_4[i]];
117117

118118
i = 0;
@@ -121,18 +121,18 @@ std::string base64Encode (unsigned char const * bytes_to_encode, unsigned int in
121121

122122
if (i != 0)
123123
{
124-
for (int j = i; j < 3; j++)
124+
for (int j = i; j < 3; j ++)
125125
char_array_3[j] = '\0';
126126

127127
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
128128
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
129129
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
130130
char_array_4[3] = char_array_3[2] & 0x3f;
131131

132-
for (int j = 0; (j < i + 1); j++)
132+
for (int j = 0; (j < i + 1); j ++)
133133
ret += base64_chars[char_array_4[j]];
134134

135-
while (i++ < 3)
135+
while (i ++ < 3)
136136
ret += '=';
137137
}
138138

src/base64.h

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

3838
#include <iostream>
3939

40-
/* base64 */
40+
/* base64 */
4141
static const std::string base64_chars =
4242
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4343
"abcdefghijklmnopqrstuvwxyz"

src/consts_enums.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define CONSTS_H
3737

3838
/* constants */
39-
#define SV_APP_VERSION "0.6.3"
39+
#define SV_APP_VERSION "0.6.4"
4040

4141
#define SV_CURRENT_YEAR "2024"
4242

src/spiritvnc.cxx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@
4242
* OF THE POSSIBILITY OF SUCH DAMAGE.
4343
*/
4444

45-
#include <FL/Fl.H>
46-
#include <FL/Fl_Double_Window.H>
47-
#include <FL/Fl_PNG_Image.H>
45+
4846
#include "app.h"
4947
#include "consts_enums.h"
5048

5149

5250
AppVars * app = new AppVars();
5351

5452

55-
/* main program */
53+
/* main program */
5654
int main (int argc, char **argv)
5755
{
5856
// tells FLTK we're a multithreaded app
@@ -103,9 +101,8 @@ int main (int argc, char **argv)
103101
#endif
104102

105103
// start up the connection 'supervisor' timer callback
106-
// do NOT change the interval of this timer
107-
// because program logic expects this to always be
108-
// near 1 second
104+
// do NOT change the interval of this timer because program
105+
// logic expects this to always be near 1 second
109106
Fl::add_timeout(SV_ONE_SECOND, svConnectionWatcher);
110107

111108
// start watching the clipboard

src/ssh.cxx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
#include "hostitem.h"
3737

3838

39-
/* attempts to close the popen'd ssh process */
40-
/* (this is called as a thread because it could block) */
39+
/*
40+
attempts to close the popen'd ssh process
41+
(this is called as a thread because it could block)
42+
*/
4143
void * svSSHCloseHelper (void * itmData)
4244
{
4345
// detach this thread
@@ -48,8 +50,6 @@ void * svSSHCloseHelper (void * itmData)
4850
if (itm == NULL || itm->sshCmdStream == NULL)
4951
return SV_RET_VOID;
5052

51-
// fprintf(itm->sshCmdStream, "%s\r\n", "exit"); // <<--- trying different way to close (below) ---<<<
52-
5353
// send 'exit' control-char sequence
5454
fprintf(itm->sshCmdStream, "\r\n%s", "~.");
5555

@@ -65,7 +65,7 @@ void * svSSHCloseHelper (void * itmData)
6565
}
6666

6767

68-
/* close and clean up ssh connection */
68+
/* close and clean up ssh connection */
6969
void svCloseSSHConnection (void * itmData)
7070
{
7171
HostItem * itm = static_cast<HostItem *>(itmData);
@@ -81,10 +81,6 @@ void svCloseSSHConnection (void * itmData)
8181
//itm->isConnecting = false;
8282
itm->hasCouldntConnect = true;
8383
itm->hasError = true;
84-
85-
//svHandleThreadConnection(itm);
86-
87-
//return;
8884
}
8985

9086
itm->isConnecting = false;

0 commit comments

Comments
 (0)