From 2018072f12417b1570da19351865eaa74ea70bb1 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 15 Jul 2020 22:54:43 -0300 Subject: [PATCH] Loading default values for uint props from windows registry. --- src/core/host.c | 1 - src/core/properties/unsigned.c | 1 + src/core/session.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- src/core/windows/registry.c | 15 ++++++++++++++- src/include/lib3270.h | 1 + 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/core/host.c b/src/core/host.c index 2205c85..f2bf29e 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -326,7 +326,6 @@ LIB3270_EXPORT const char * lib3270_get_default_host(const H3270 GNUC_UNUSED(*hS RegCloseKey(hKey); - trace("***************** %d",dwRet); if(dwRet == ERROR_SUCCESS) { default_host = (char *) realloc(default_host,cbData+1); diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index cecdede..4a8264e 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -147,6 +147,7 @@ static unsigned int lib3270_get_host_type_number(const H3270 *hSession) { .name = "unlock_delay", // Property name. + .group = LIB3270_ACTION_GROUP_OFFLINE, // Property group. #ifdef UNLOCK_MS .default_value = UNLOCK_MS, #else diff --git a/src/core/session.c b/src/core/session.c index 60bd8a3..7d920d2 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -24,8 +24,6 @@ * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) * */ @@ -47,7 +45,7 @@ #include "../ssl/crl.h" #include #include - +#include /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ @@ -364,15 +362,62 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->pointer = (unsigned short) LIB3270_POINTER_LOCKED; #ifdef UNLOCK_MS - hSession->unlock_delay_ms = UNLOCK_MS; + lib3270_set_unlock_delay(hSession,UNLOCK_MS); #else - hSession->unlock_delay_ms = 350; + lib3270_set_unlock_delay(hSession,350); #endif // UNLOCK_MS // CSD for(f=0;f<4;f++) hSession->csd[f] = hSession->saved_csd[f] = LIB3270_ANSI_CSD_US; +#ifdef _WIN32 + // Get defaults from registry. + { + HKEY hKey; + DWORD disp = 0; + LSTATUS rc = RegCreateKeyEx( + HKEY_LOCAL_MACHINE, + "Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME) "\\protocol", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_QUERY_VALUE|KEY_READ, + NULL, + &hKey, + &disp); + + if(rc == ERROR_SUCCESS) + { + size_t property; + const LIB3270_UINT_PROPERTY * uiProps = lib3270_get_unsigned_properties_list(); + + for(property = 0; uiProps[property].name;property++) + { + if(!(uiProps[property].set && uiProps[property].group == LIB3270_ACTION_GROUP_OFFLINE)) + continue; + + DWORD val = (DWORD) uiProps[property].default_value; + DWORD cbData = sizeof(DWORD); + DWORD dwRet = RegQueryValueEx(hKey, uiProps[property].name, NULL, NULL, (LPBYTE) &val, &cbData); + + if(dwRet == ERROR_SUCCESS) + { + debug("%s=%u",uiProps[property].name,(unsigned int) val); + uiProps[property].set(hSession,(unsigned int) val); + } + else + { + uiProps[property].set(hSession,uiProps[property].default_value); + } + + } + + RegCloseKey(hKey); + } + } +#endif // _WIN32 + // Initialize toggles initialize_toggles(hSession); diff --git a/src/core/windows/registry.c b/src/core/windows/registry.c index bd52cc7..32ba09a 100644 --- a/src/core/windows/registry.c +++ b/src/core/windows/registry.c @@ -36,7 +36,7 @@ #include #include -LSTATUS lib3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY phkResult) { +LIB3270_EXPORT LSTATUS lib3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY phkResult) { LSTATUS rc; DWORD disp; @@ -55,3 +55,16 @@ LSTATUS lib3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY ph return rc; } + +LIB3270_EXPORT DWORD lib3270_win32_get_dword(HKEY hKey, const char *name, DWORD def) +{ + DWORD val = def; + DWORD cbData = sizeof(DWORD); + + DWORD dwRet = RegQueryValueEx(hKey, name, NULL, NULL, (LPBYTE) &val, &cbData); + + if(dwRet != ERROR_SUCCESS) + return def; + + return val; +} diff --git a/src/include/lib3270.h b/src/include/lib3270.h index c500e86..6e49a94 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1561,6 +1561,7 @@ LIB3270_EXPORT const char * lib3270_win32_strerror(int e); LIB3270_EXPORT const char * lib3270_win32_local_charset(void); LIB3270_EXPORT LSTATUS lib3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY phkResult); + LIB3270_EXPORT DWORD lib3270_win32_get_dword(HKEY hKey, const char *name, DWORD def); /** * @brief Translate windows error code. -- libgit2 0.21.2