Commit c4300650bbacfff454cf40bb5d6e60debeb2e852

Authored by Perry Werneck
1 parent 9f5e1712

Getting default URL from windows registry.

Showing 1 changed file with 49 additions and 6 deletions   Show diff stats
src/core/host.c
@@ -288,16 +288,59 @@ LIB3270_EXPORT const char * lib3270_get_url(const H3270 *hSession) @@ -288,16 +288,59 @@ LIB3270_EXPORT const char * lib3270_get_url(const H3270 *hSession)
288 if(hSession->host.url) 288 if(hSession->host.url)
289 return hSession->host.url; 289 return hSession->host.url;
290 290
291 -#ifdef LIB3270_DEFAULT_HOST  
292 - return LIB3270_DEFAULT_HOST;  
293 -#else  
294 - return getenv("LIB3270_DEFAULT_HOST");  
295 -#endif // LIB3270_DEFAULT_HOST  
296 - 291 + return lib3270_get_default_host(hSession);
297 } 292 }
298 293
299 LIB3270_EXPORT const char * lib3270_get_default_host(const H3270 GNUC_UNUSED(*hSession)) 294 LIB3270_EXPORT const char * lib3270_get_default_host(const H3270 GNUC_UNUSED(*hSession))
300 { 295 {
  296 +#ifdef _WIN32
  297 + {
  298 + HKEY hKey;
  299 + DWORD disp = 0;
  300 + LSTATUS rc = RegCreateKeyEx(
  301 + HKEY_LOCAL_MACHINE,
  302 + "Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),
  303 + 0,
  304 + NULL,
  305 + REG_OPTION_NON_VOLATILE,
  306 + KEY_QUERY_VALUE|KEY_READ,
  307 + NULL,
  308 + &hKey,
  309 + &disp);
  310 +
  311 + if(rc == ERROR_SUCCESS)
  312 + {
  313 + static char * default_host = NULL;
  314 + DWORD cbData = 4096;
  315 +
  316 + if(!default_host)
  317 + {
  318 + default_host = (char *) malloc(cbData+1);
  319 + }
  320 + else
  321 + {
  322 + default_host = (char *) realloc(default_host,cbData+1);
  323 + }
  324 +
  325 + DWORD dwRet = RegQueryValueEx(hKey,"host",NULL,NULL,(LPBYTE) default_host, &cbData);
  326 +
  327 + RegCloseKey(hKey);
  328 +
  329 + trace("***************** %d",dwRet);
  330 + if(dwRet == ERROR_SUCCESS)
  331 + {
  332 + default_host = (char *) realloc(default_host,cbData+1);
  333 + default_host[cbData] = 0;
  334 + return default_host;
  335 + }
  336 +
  337 + free(default_host);
  338 + default_host = NULL;
  339 +
  340 + }
  341 + }
  342 +#endif // _WIN32
  343 +
301 #ifdef LIB3270_DEFAULT_HOST 344 #ifdef LIB3270_DEFAULT_HOST
302 return LIB3270_DEFAULT_HOST; 345 return LIB3270_DEFAULT_HOST;
303 #else 346 #else