Added option to set the listen address via the win32 GUI. This

allows the user to specify one (and only one) network interface
to listen on.
This commit is contained in:
crs 2004-11-01 18:21:00 +00:00
parent 519871fe15
commit 58de7a21fe
4 changed files with 85 additions and 32 deletions

View File

@ -19,6 +19,7 @@
#include "CArchMiscWindows.h" #include "CArchMiscWindows.h"
#include "CAdvancedOptions.h" #include "CAdvancedOptions.h"
#include "LaunchUtil.h" #include "LaunchUtil.h"
#include "XArch.h"
#include "resource.h" #include "resource.h"
// //
@ -32,7 +33,8 @@ CAdvancedOptions::CAdvancedOptions(HWND parent, CConfig* config) :
m_config(config), m_config(config),
m_isClient(false), m_isClient(false),
m_screenName(ARCH->getHostName()), m_screenName(ARCH->getHostName()),
m_port(kDefaultPort) m_port(kDefaultPort),
m_interface()
{ {
assert(s_singleton == NULL); assert(s_singleton == NULL);
s_singleton = this; s_singleton = this;
@ -67,6 +69,12 @@ CAdvancedOptions::getPort() const
return m_port; return m_port;
} }
CString
CAdvancedOptions::getInterface() const
{
return m_interface;
}
CString CString
CAdvancedOptions::getCommandLine(bool isClient, const CString& serverName) const CAdvancedOptions::getCommandLine(bool isClient, const CString& serverName) const
{ {
@ -88,7 +96,11 @@ CAdvancedOptions::getCommandLine(bool isClient, const CString& serverName) const
cmdLine += portString; cmdLine += portString;
} }
else { else {
cmdLine += " --address :"; cmdLine += " --address ";
if (!m_interface.empty()) {
cmdLine += m_interface;
}
cmdLine += ":";
cmdLine += portString; cmdLine += portString;
} }
@ -101,14 +113,19 @@ CAdvancedOptions::init()
// get values from registry // get values from registry
HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath()); HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath());
if (key != NULL) { if (key != NULL) {
DWORD newPort = CArchMiscWindows::readValueInt(key, "port"); DWORD newPort = CArchMiscWindows::readValueInt(key, "port");
CString newName = CArchMiscWindows::readValueString(key, "name"); CString newName = CArchMiscWindows::readValueString(key, "name");
CString newInterface =
CArchMiscWindows::readValueString(key, "interface");
if (newPort != 0) { if (newPort != 0) {
m_port = static_cast<int>(newPort); m_port = static_cast<int>(newPort);
} }
if (!newName.empty()) { if (!newName.empty()) {
m_screenName = newName; m_screenName = newName;
} }
if (!newInterface.empty()) {
m_interface = newInterface;
}
CArchMiscWindows::closeKey(key); CArchMiscWindows::closeKey(key);
} }
} }
@ -125,11 +142,16 @@ CAdvancedOptions::doInit(HWND hwnd)
child = getItem(hwnd, IDC_ADVANCED_NAME_EDIT); child = getItem(hwnd, IDC_ADVANCED_NAME_EDIT);
SendMessage(child, WM_SETTEXT, 0, (LPARAM)m_screenName.c_str()); SendMessage(child, WM_SETTEXT, 0, (LPARAM)m_screenName.c_str());
child = getItem(hwnd, IDC_ADVANCED_INTERFACE_EDIT);
SendMessage(child, WM_SETTEXT, 0, (LPARAM)m_interface.c_str());
} }
bool bool
CAdvancedOptions::save(HWND hwnd) CAdvancedOptions::save(HWND hwnd)
{ {
SetCursor(LoadCursor(NULL, IDC_WAIT));
HWND child = getItem(hwnd, IDC_ADVANCED_NAME_EDIT); HWND child = getItem(hwnd, IDC_ADVANCED_NAME_EDIT);
CString name = getWindowText(child); CString name = getWindowText(child);
if (!m_config->isValidScreenName(name)) { if (!m_config->isValidScreenName(name)) {
@ -147,6 +169,23 @@ CAdvancedOptions::save(HWND hwnd)
return false; return false;
} }
child = getItem(hwnd, IDC_ADVANCED_INTERFACE_EDIT);
CString iface = getWindowText(child);
if (!m_isClient) {
try {
if (!iface.empty()) {
ARCH->nameToAddr(iface);
}
}
catch (XArchNetworkName& e) {
showError(hwnd, CStringUtil::format(
getString(IDS_INVALID_INTERFACE_NAME).c_str(),
iface.c_str(), e.what().c_str()));
SetFocus(child);
return false;
}
}
// get and verify port // get and verify port
child = getItem(hwnd, IDC_ADVANCED_PORT_EDIT); child = getItem(hwnd, IDC_ADVANCED_PORT_EDIT);
CString portString = getWindowText(child); CString portString = getWindowText(child);
@ -164,12 +203,14 @@ CAdvancedOptions::save(HWND hwnd)
// save state // save state
m_screenName = name; m_screenName = name;
m_port = port; m_port = port;
m_interface = iface;
// save values to registry // save values to registry
HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath()); HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath());
if (key != NULL) { if (key != NULL) {
CArchMiscWindows::setValue(key, "port", m_port); CArchMiscWindows::setValue(key, "port", m_port);
CArchMiscWindows::setValue(key, "name", m_screenName); CArchMiscWindows::setValue(key, "name", m_screenName);
CArchMiscWindows::setValue(key, "interface", m_interface);
CArchMiscWindows::closeKey(key); CArchMiscWindows::closeKey(key);
} }
@ -182,6 +223,7 @@ CAdvancedOptions::setDefaults(HWND hwnd)
// restore defaults // restore defaults
m_screenName = ARCH->getHostName(); m_screenName = ARCH->getHostName();
m_port = kDefaultPort; m_port = kDefaultPort;
m_interface = "";
// update GUI // update GUI
doInit(hwnd); doInit(hwnd);

View File

@ -47,6 +47,9 @@ public:
//! Get the port //! Get the port
int getPort() const; int getPort() const;
//! Get the interface
CString getInterface() const;
//! Convert options to command line string //! Convert options to command line string
CString getCommandLine(bool isClient, CString getCommandLine(bool isClient,
const CString& serverName) const; const CString& serverName) const;
@ -71,6 +74,7 @@ private:
bool m_isClient; bool m_isClient;
CString m_screenName; CString m_screenName;
int m_port; int m_port;
CString m_interface;
}; };
#endif #endif

View File

@ -106,7 +106,7 @@ BEGIN
PUSHBUTTON "Quit",IDCANCEL,243,241,50,14 PUSHBUTTON "Quit",IDCANCEL,243,241,50,14
END END
IDD_ADD DIALOG DISCARDABLE 0, 0, 192, 236 IDD_ADD DIALOG DISCARDABLE 0, 0, 192, 254
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "Add Screen" CAPTION "Add Screen"
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif"
@ -116,33 +116,33 @@ BEGIN
LTEXT "&Aliases:",IDC_STATIC,7,25,25,8 LTEXT "&Aliases:",IDC_STATIC,7,25,25,8
EDITTEXT IDC_ADD_ALIASES_EDIT,79,26,106,40,ES_MULTILINE | EDITTEXT IDC_ADD_ALIASES_EDIT,79,26,106,40,ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
GROUPBOX "Half-Duplex",IDC_STATIC,7,72,178,64 GROUPBOX "Options",IDC_STATIC,7,72,178,80
LTEXT "If your Caps, Num, or Scroll Lock keys behave strangely on this screen then turn on the half-duplex options and restart the server.", LTEXT "If your Caps, Num, or Scroll Lock keys behave strangely on this client screen then try turning the half-duplex options on and reconnect the client.",
IDC_STATIC,13,82,165,25 IDC_STATIC,13,82,165,25
CONTROL "&Caps Lock",IDC_ADD_HD_CAPS_CHECK,"Button", CONTROL "Half-duplex &Caps Lock",IDC_ADD_HD_CAPS_CHECK,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,110,81,10 BS_AUTOCHECKBOX | WS_TABSTOP,13,110,165,10
CONTROL "&Num Lock",IDC_ADD_HD_NUM_CHECK,"Button", CONTROL "Half-duplex &Num Lock",IDC_ADD_HD_NUM_CHECK,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,122,81,10 BS_AUTOCHECKBOX | WS_TABSTOP,13,122,165,10
CONTROL "Sc&roll Lock",IDC_ADD_HD_SCROLL_CHECK,"Button", CONTROL "Half-duplex Sc&roll Lock",IDC_ADD_HD_SCROLL_CHECK,
BS_AUTOCHECKBOX | WS_TABSTOP,98,110,81,10 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,134,165,10
GROUPBOX "Modifiers",IDC_STATIC,7,139,178,65 GROUPBOX "Modifiers",IDC_STATIC,7,155,178,65
LTEXT "Shift",IDC_STATIC,13,155,15,8 LTEXT "Shift",IDC_STATIC,13,171,15,8
COMBOBOX IDC_ADD_MOD_SHIFT,37,152,48,60,CBS_DROPDOWNLIST | COMBOBOX IDC_ADD_MOD_SHIFT,37,168,48,60,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP WS_VSCROLL | WS_TABSTOP
LTEXT "Ctrl",IDC_STATIC,13,170,11,8 LTEXT "Ctrl",IDC_STATIC,13,186,11,8
COMBOBOX IDC_ADD_MOD_CTRL,37,168,48,60,CBS_DROPDOWNLIST | COMBOBOX IDC_ADD_MOD_CTRL,37,184,48,60,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP WS_VSCROLL | WS_TABSTOP
LTEXT "Alt",IDC_STATIC,13,186,9,8 LTEXT "Alt",IDC_STATIC,13,202,9,8
COMBOBOX IDC_ADD_MOD_ALT,37,184,48,60,CBS_DROPDOWNLIST | COMBOBOX IDC_ADD_MOD_ALT,37,200,48,60,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP WS_VSCROLL | WS_TABSTOP
LTEXT "Meta",IDC_STATIC,101,154,17,8 LTEXT "Meta",IDC_STATIC,101,170,17,8
COMBOBOX IDC_ADD_MOD_META,125,152,48,60,CBS_DROPDOWNLIST | COMBOBOX IDC_ADD_MOD_META,125,168,48,60,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP WS_VSCROLL | WS_TABSTOP
LTEXT "Super",IDC_STATIC,101,170,20,8 LTEXT "Super",IDC_STATIC,101,186,20,8
COMBOBOX IDC_ADD_MOD_SUPER,125,168,48,60,CBS_DROPDOWNLIST | COMBOBOX IDC_ADD_MOD_SUPER,125,184,48,60,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,79,215,50,14 DEFPUSHBUTTON "OK",IDOK,79,233,50,14
PUSHBUTTON "Cancel",IDCANCEL,135,215,50,14 PUSHBUTTON "Cancel",IDCANCEL,135,233,50,14
END END
IDD_WAIT DIALOG DISCARDABLE 0, 0, 186, 54 IDD_WAIT DIALOG DISCARDABLE 0, 0, 186, 54
@ -215,7 +215,7 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,150,248,50,14 PUSHBUTTON "Cancel",IDCANCEL,150,248,50,14
END END
IDD_ADVANCED_OPTIONS DIALOG DISCARDABLE 0, 0, 230, 133 IDD_ADVANCED_OPTIONS DIALOG DISCARDABLE 0, 0, 230, 186
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Advanced Options" CAPTION "Advanced Options"
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif"
@ -229,9 +229,13 @@ BEGIN
LTEXT "&Port:",IDC_STATIC,7,90,16,8 LTEXT "&Port:",IDC_STATIC,7,90,16,8
EDITTEXT IDC_ADVANCED_PORT_EDIT,63,88,40,12,ES_AUTOHSCROLL | EDITTEXT IDC_ADVANCED_PORT_EDIT,63,88,40,12,ES_AUTOHSCROLL |
ES_NUMBER ES_NUMBER
PUSHBUTTON "&Defaults",IDC_ADVANCED_DEFAULTS,7,112,50,14 LTEXT "The server normally listens for client connections on all network interfaces. Enter the address of a particular interface to listen on just that interface.",
DEFPUSHBUTTON "OK",IDOK,118,112,50,14 IDC_STATIC,7,110,216,26
PUSHBUTTON "Cancel",IDCANCEL,173,112,50,14 LTEXT "&Interface:",IDC_STATIC,7,144,31,8
EDITTEXT IDC_ADVANCED_INTERFACE_EDIT,63,142,81,12,ES_AUTOHSCROLL
PUSHBUTTON "&Defaults",IDC_ADVANCED_DEFAULTS,7,165,50,14
DEFPUSHBUTTON "OK",IDOK,118,165,50,14
PUSHBUTTON "Cancel",IDCANCEL,173,165,50,14
END END
@ -256,7 +260,7 @@ BEGIN
LEFTMARGIN, 7 LEFTMARGIN, 7
RIGHTMARGIN, 185 RIGHTMARGIN, 185
TOPMARGIN, 7 TOPMARGIN, 7
BOTTOMMARGIN, 229 BOTTOMMARGIN, 247
END END
IDD_WAIT, DIALOG IDD_WAIT, DIALOG
@ -288,7 +292,7 @@ BEGIN
LEFTMARGIN, 7 LEFTMARGIN, 7
RIGHTMARGIN, 223 RIGHTMARGIN, 223
TOPMARGIN, 7 TOPMARGIN, 7
BOTTOMMARGIN, 126 BOTTOMMARGIN, 179
END END
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
@ -360,6 +364,7 @@ BEGIN
IDS_ERROR_CODE "Error code: %{1}" IDS_ERROR_CODE "Error code: %{1}"
IDS_AUTOSTART_PERMISSION_ALL IDS_AUTOSTART_PERMISSION_ALL
"You have sufficient access rights to install and uninstall Auto Start for all users or for just yourself." "You have sufficient access rights to install and uninstall Auto Start for all users or for just yourself."
IDS_INVALID_INTERFACE_NAME "The interface '%{1}' is invalid: %{2}"
END END
#endif // English (U.S.) resources #endif // English (U.S.) resources

View File

@ -43,6 +43,7 @@
#define IDS_INVALID_TIME 39 #define IDS_INVALID_TIME 39
#define IDS_ERROR_CODE 39 #define IDS_ERROR_CODE 39
#define IDS_AUTOSTART_PERMISSION_ALL 40 #define IDS_AUTOSTART_PERMISSION_ALL 40
#define IDS_INVALID_INTERFACE_NAME 41
#define IDD_MAIN 101 #define IDD_MAIN 101
#define IDD_ADD 102 #define IDD_ADD 102
#define IDD_WAIT 103 #define IDD_WAIT 103
@ -89,6 +90,7 @@
#define IDC_ADVANCED_PORT_EDIT 1039 #define IDC_ADVANCED_PORT_EDIT 1039
#define IDC_ADD_HD_SCROLL_CHECK 1039 #define IDC_ADD_HD_SCROLL_CHECK 1039
#define IDC_MAIN_DEBUG 1040 #define IDC_MAIN_DEBUG 1040
#define IDC_ADVANCED_INTERFACE_EDIT 1040
#define IDC_GLOBAL_DELAY_CHECK 1041 #define IDC_GLOBAL_DELAY_CHECK 1041
#define IDC_GLOBAL_DELAY_TIME 1042 #define IDC_GLOBAL_DELAY_TIME 1042
#define IDC_GLOBAL_TWO_TAP_CHECK 1043 #define IDC_GLOBAL_TWO_TAP_CHECK 1043