From c4300650bbacfff454cf40bb5d6e60debeb2e852 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 15 Jul 2020 10:55:14 -0300 Subject: [PATCH] Getting default URL from windows registry. --- src/core/host.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/core/host.c b/src/core/host.c index 1dcf440..2205c85 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -288,16 +288,59 @@ LIB3270_EXPORT const char * lib3270_get_url(const H3270 *hSession) if(hSession->host.url) return hSession->host.url; -#ifdef LIB3270_DEFAULT_HOST - return LIB3270_DEFAULT_HOST; -#else - return getenv("LIB3270_DEFAULT_HOST"); -#endif // LIB3270_DEFAULT_HOST - + return lib3270_get_default_host(hSession); } LIB3270_EXPORT const char * lib3270_get_default_host(const H3270 GNUC_UNUSED(*hSession)) { +#ifdef _WIN32 + { + HKEY hKey; + DWORD disp = 0; + LSTATUS rc = RegCreateKeyEx( + HKEY_LOCAL_MACHINE, + "Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_QUERY_VALUE|KEY_READ, + NULL, + &hKey, + &disp); + + if(rc == ERROR_SUCCESS) + { + static char * default_host = NULL; + DWORD cbData = 4096; + + if(!default_host) + { + default_host = (char *) malloc(cbData+1); + } + else + { + default_host = (char *) realloc(default_host,cbData+1); + } + + DWORD dwRet = RegQueryValueEx(hKey,"host",NULL,NULL,(LPBYTE) default_host, &cbData); + + RegCloseKey(hKey); + + trace("***************** %d",dwRet); + if(dwRet == ERROR_SUCCESS) + { + default_host = (char *) realloc(default_host,cbData+1); + default_host[cbData] = 0; + return default_host; + } + + free(default_host); + default_host = NULL; + + } + } +#endif // _WIN32 + #ifdef LIB3270_DEFAULT_HOST return LIB3270_DEFAULT_HOST; #else -- libgit2 0.21.2