/[winpt]/trunk/Src/wptRegistry.cpp
ViewVC logotype

Contents of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 85 - (show annotations)
Fri Nov 18 07:20:40 2005 UTC (19 years, 3 months ago) by twoaday
File size: 18209 byte(s)
2005-11-17  Timo Schulz  <ts@g10code.com>
 
        * wptGPG.cpp (check_last_gnupg_access): Kludge to avoid that
        the cache will be loaded twice.
        * wptRegistry.cpp (regist_inst_winpt): More comments.
        * wptKeyManagerDlg.cpp (do_center_window): Make sure that
        neg. coordinates are never used.
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Localize all
        strings.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Likewise.
        * wptFileManagerDlg.cpp (filemanager_dlg_proc): Localize menu
        and save 'AlwaysOnTop' in the registry.
         

1 /* wptRegistry.cpp - W32 Registry access
2 * Copyright (C) 2000-2005 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * WinPT is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with WinPT; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <stdio.h>
27
28 #include "wptErrors.h"
29 #include "wptW32API.h"
30 #include "wptGPG.h"
31 #include "wptRegistry.h"
32 #include "wptKeyserver.h"
33 #include "wptTypes.h"
34 #include "wptNLS.h"
35 #include "wptVersion.h"
36
37 #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
38
39 static gpg_filetype gpg_filetypes[] = {
40 {"GPG Detached Signature", ".sig", 1},
41 {"GPG Encrypted Data", ".gpg", 2},
42 {"GPG Armored Data", ".asc", 2},
43 {0}
44 };
45
46 struct reg_hotkey_s reg_hotkeys[] = {
47 {"ClipEncrypt", "", 0},
48 {"ClipDecrypt", "", 0},
49 {"ClipSign", "", 0},
50 {"ClipSignEnc", "", 0},
51 {"CwsEncrypt", "", 0},
52 {"CwsDecrypt", "", 0},
53 {"CwsSign", "", 0},
54 {"CwsSignEnc", "", 0},
55 {NULL, "", 0}
56 };
57
58 winpt_reg_prefs_s reg_prefs;
59
60 #define WINPT_REG "Software\\WinPT"
61
62
63 void
64 free_reg_prefs (void)
65 {
66 free_if_alloc (reg_prefs.backup.path);
67 free_if_alloc (reg_prefs.kserv_conf);
68 free_if_alloc (reg_prefs.homedir);
69 memset (&reg_prefs, 0, sizeof reg_prefs);
70 } /* free_reg_prefs */
71
72
73 /* Register the given WinPT filetype. */
74 static int
75 regist_single_filetype (gpg_filetype *gfile)
76 {
77 char icon[256], prog[256];
78
79 memset (&icon, 0, sizeof (icon));
80 GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
81 _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
82 return create_file_type (prog, gfile->ext, gfile->descr, icon);
83 } /* regist_single_filetype */
84
85
86 /* Install the GPG related into the W32 resgistry, if the entry already
87 exists the function returns immediately. */
88 int
89 regist_inst_gnupg (int create_mokey)
90 {
91 int rc;
92 HKEY reg;
93
94 rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, &reg );
95 if( rc_ok( rc ) ) {
96 RegCloseKey( reg );
97 return 0;
98 }
99 rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", &reg );
100 if( !rc_ok( rc ) )
101 return WPTERR_REGISTRY;
102 RegCloseKey( reg );
103 if( create_mokey ) {
104 rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", 0, KEY_READ, &reg );
105 if( rc_ok( rc ) ) {
106 RegCloseKey( reg );
107 return 0;
108 }
109 rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", &reg );
110 if( !rc_ok( rc ) )
111 return WPTERR_REGISTRY;
112 RegCloseKey( reg );
113 }
114
115 return 0;
116 } /* regist_inst_gpg */
117
118
119 /* Install WinPT into the W32 registry, if the entry already
120 exists the function returns immediately. @with_ext can be
121 used to register some file types (if 1). @created contains
122 1 if the registry key was created.
123 Return value: 0 on success. */
124 int
125 regist_inst_winpt (int with_ext, int * created)
126 {
127 HKEY reg;
128 char *p = NULL;
129 char modpath[MAX_PATH+1];
130 int rc, i, id, n = 0;
131
132 if (created)
133 *created = 0;
134
135 p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
136 if (p && *p == '1')
137 with_ext = 0;
138 free_if_alloc (p);
139
140 if (with_ext) {
141 id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can "
142 "be processed with a double click in the explorer.\n"
143 "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
144 if (id == IDNO) {
145 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
146 goto start;
147 }
148 for (i = 0; gpg_filetypes[i].ext; i++) {
149 rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
150 if (rc_ok (rc)) {
151 RegCloseKey (reg);
152 id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
153 _("It seems there was already a '%s' file type registered by another application.\n"
154 "Do you want to overwrite it?"), gpg_filetypes[i].ext);
155 if (id == IDNO)
156 continue;
157 }
158 regist_single_filetype (&gpg_filetypes[i]);
159 n++;
160 }
161 }
162
163 start:
164 rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
165 if (rc_ok (rc)) {
166 RegCloseKey (reg);
167 rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
168 if (!rc_ok (rc)) {
169 RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
170 RegCloseKey (reg);
171 }
172 p = get_reg_entry_keyserver ("Default");
173 if (!p) {
174 char buf[16];
175 sprintf (buf, "%d", HKP_PORT);
176 set_reg_entry_keyserver ("Default_Port", buf);
177 set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
178 }
179 free_if_alloc (p);
180 if (n)
181 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
182 return 0;
183 }
184 rc = RegCreateKey(HKEY_CURRENT_USER, WINPT_REG, &reg);
185 if (!rc_ok (rc))
186 return WPTERR_REGISTRY;
187 if (created)
188 *created = 1;
189 RegCloseKey (reg);
190 if (n)
191 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
192 if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
193 while (n-- > 0) {
194 if (modpath[n] == '\\') {
195 modpath[n] = 0;
196 break;
197 }
198 }
199 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG,
200 "Install Directory", modpath);
201 }
202
203 return 0;
204 }
205
206
207 /* Create a new filetype in the W32 registry.
208 We should really care of errors! Otherwise we can damage the registry! */
209 int
210 create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )
211 {
212 int rc;
213 HKEY reg = NULL;
214 char deficon[256], defexec[256], p_exefile[256];
215
216
217 rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, &reg );
218 if( rc_ok( rc ) )
219 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) );
220 if( rc_ok( rc ) )
221 rc = RegCloseKey( reg );
222 if( rc_ok( rc ) )
223 rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );
224 if( rc_ok( rc ) )
225 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) );
226 if( rc_ok( rc ) )
227 rc = RegCloseKey( reg );
228 if( !rc_ok( rc ) ) {
229 rc = WPTERR_REGISTRY;
230 goto leave;
231 }
232
233 memset( &deficon, 0, sizeof deficon );
234 _snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname );
235 memset( &defexec, 0, sizeof defexec );
236 _snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname );
237 memset( &p_exefile, 0, sizeof p_exefile );
238 _snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile );
239
240 rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );
241 if( rc_ok( rc ) )
242 rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) );
243 if( rc_ok( rc ) )
244 rc = RegCloseKey( reg );
245 if( rc_ok( rc ) )
246 rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );
247 if( rc_ok( rc ) )
248 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) );
249 if( rc_ok( rc ) )
250 rc = RegCloseKey( reg );
251 if( !rc_ok( rc ) ) {
252 rc = WPTERR_REGISTRY;
253 goto leave;
254 }
255
256 leave:
257 if( reg )
258 RegCloseKey( reg );
259 return rc;
260 } /* create_file_type */
261
262
263 /* Expand a string with %foo% entries so that %foo% will
264 be replaced with its actual value. */
265 static char *
266 expand_path (const char *path)
267 {
268 DWORD len;
269 char *p;
270
271 len = ExpandEnvironmentStrings (path, NULL, 0);
272 if (!len)
273 return NULL;
274 len += 1;
275 p = new char[len+1];
276 if( !p )
277 return NULL;
278 len = ExpandEnvironmentStrings (path, p, len);
279 if (!len) {
280 free_if_alloc (p);
281 return NULL;
282 }
283 return p;
284 } /* expand_path */
285
286
287 /* Retrieve a registry entry with the directory given in @dir
288 and the key given in @key.
289 Return value is the value or NULL otherwise. */
290 char*
291 get_reg_entry (HKEY root_key, const char * dir, const char * key)
292 {
293 int rc;
294 char text[384] = {0};
295 DWORD nbytes, type;
296 HKEY reg_key = NULL;
297 char *p = NULL;
298
299 rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
300 if( !rc_ok( rc ) )
301 goto leave;
302 nbytes = sizeof (text) - 1;
303 type = REG_SZ;
304
305 rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes);
306 if (!rc_ok (rc) || !nbytes)
307 goto leave;
308
309 if (type == REG_EXPAND_SZ && strchr (text, '%'))
310 p = expand_path (text);
311 else {
312 p = new char[nbytes + 1];
313 if (!p)
314 BUG (0);
315 memcpy (p, text, nbytes);
316 p[nbytes] = '\0';
317 }
318
319 leave:
320 if (reg_key)
321 RegCloseKey (reg_key);
322 return p;
323 }
324
325
326 /* XXX: use REG_EXPAND_SZ to support multi user environments.
327 keep this type and do not overwrite it with REG_SZ. */
328
329 /* Set a registry entry. */
330 int
331 set_reg_entry (HKEY root_key, const char *dir, const char *key,
332 const char *value)
333 {
334 int rc = 0;
335 HKEY reg_key;
336
337 rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );
338 if( !rc_ok( rc ) )
339 return WPTERR_REGISTRY;
340 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
341 if( !rc_ok( rc ) )
342 rc = WPTERR_REGISTRY;
343 RegCloseKey( reg_key );
344 return rc;
345 } /* set_reg_entry */
346
347
348 int
349 set_reg_key( HKEY root_key, const char * dir, const char * key,
350 const char * value )
351 {
352 int rc = 0;
353 HKEY reg_key;
354
355 rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );
356 if( !rc_ok( rc ) )
357 return WPTERR_REGISTRY;
358
359 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
360 if( !rc_ok( rc ) ) {
361 if ( RegCreateKey( root_key, key, &reg_key ) != ERROR_SUCCESS ) {
362 rc = WPTERR_REGISTRY;
363 goto leave;
364 }
365 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
366 if ( !rc_ok( rc ) )
367 rc = WPTERR_REGISTRY;
368 }
369
370 leave:
371 RegCloseKey( reg_key );
372 return rc;
373 } /* set_reg_key */
374
375
376 int
377 set_reg_entry_gpg (const char * key, const char * value)
378 {
379 return set_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value);
380 }
381
382
383 int
384 set_reg_entry_mo (const char * value)
385 {
386 return set_reg_entry (HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS",
387 "MODir", value);
388 }
389
390
391 char *
392 get_reg_entry_gpg (const char *key)
393 {
394 return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
395 }
396
397
398 /* Return if possible the GPG4Win installation directory concatenated
399 with the string in @path if given. */
400 char*
401 get_reg_entry_gpg4win (const char *path)
402 {
403 char *p, *pp;
404 p = get_reg_entry (HKEY_LOCAL_MACHINE,
405 "Software\\GNU\\GnuPG", "Install Directory");
406 if (!p)
407 return NULL;
408 if (!path)
409 return p;
410 pp = new char[strlen (p) + strlen (path) + 4];
411 if (!pp)
412 BUG (NULL);
413 sprintf (pp, "%s\\%s", p, path);
414 free_if_alloc (p);
415 return pp;
416 }
417
418
419 char*
420 get_reg_entry_mo (void)
421 {
422 char *p, *pp;
423 const char *lang;
424
425 p = get_reg_entry (HKEY_CURRENT_USER,
426 "Control Panel\\Mingw32\\NLS", "MODir");
427 if (p)
428 return p;
429
430 lang = get_gettext_langid ();
431 if (!lang)
432 return NULL;
433 pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
434 if (!pp)
435 BUG (NULL);
436 sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
437 p = get_reg_entry_gpg4win (pp);
438 free_if_alloc (pp);
439 return p;
440 }
441
442
443 /* All valid configuration commands. */
444 static const char * cfg [] = {
445 NULL,
446 "CacheTime",
447 "WordWrap",
448 "FastMode",
449 "Viewer",
450 "KeylistMode",
451 "WipeMode",
452 "AlwaysTrust",
453 "AutoBackup",
454 "BackupMode",
455 "DisableHotkeys",
456 "NoCompressMultiMedia",
457 "Expert",
458 "FMProgressBar",
459 };
460
461
462 int
463 set_reg_winpt_single (int id, int val)
464 {
465 char buf[64];
466 int rc;
467
468 sprintf (buf, "%d", val);
469 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);
470 return rc;
471 }
472
473
474 int
475 get_reg_winpt_single (int id)
476 {
477 char * buf = NULL;
478 int val = 0;
479
480 buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);
481 if (buf && *buf != ' ')
482 val = 1;
483 else if (!buf)
484 val = -1;
485 free_if_alloc (buf);
486 return val;
487 }
488
489
490 /* Saves the winpt preferences in the registry. */
491 int
492 set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
493 {
494 char buf[128];
495 size_t i;
496 int rc = 0;
497
498 for (i=1; i < DIM (cfg); i++) {
499 switch (i) {
500 case CFG_CACHETIME:
501 sprintf (buf, "%d", opt->cache_time);
502 break;
503 case CFG_WORDWRAP:
504 sprintf (buf, "%d", opt->word_wrap);
505 break;
506 case CFG_WIPEMODE:
507 sprintf (buf, "%d", opt->wipe_mode);
508 break;
509 case CFG_FASTMODE:
510 sprintf (buf, "%d", opt->use_tmpfiles);
511 break;
512 case CFG_NOZIP_MMEDIA:
513 sprintf (buf, "%d", opt->no_zip_mmedia);
514 break;
515 case CFG_VIEWER:
516 sprintf (buf, "%d", opt->use_viewer);
517 break;
518 case CFG_KEYLISTMODE:
519 sprintf (buf, "%d", opt->keylist_mode);
520 break;
521 case CFG_ALWAYSTRUST:
522 sprintf (buf, "%d", opt->always_trust);
523 break;
524 case CFG_AUTOBACKUP:
525 sprintf (buf, "%d", opt->auto_backup);
526 break;
527 case CFG_AUTOBAKMODE:
528 sprintf (buf, "%d", opt->backup.mode);
529 break;
530 case CFG_DISHOTKEYS:
531 sprintf (buf, "%d", opt->no_hotkeys);
532 break;
533 case CFG_EXPERT:
534 sprintf (buf, "%d", opt->expert);
535 break;
536
537 case CFG_FM_PROGRESS:
538 sprintf (buf, "%d", opt->fm.progress);
539 break;
540 }
541 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);
542 if (rc)
543 goto leave;
544 }
545
546 if (opt->backup.path) {
547 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath",
548 opt->backup.path);
549 if (rc)
550 goto leave;
551 }
552 if (opt->kserv_conf) {
553 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",
554 opt->kserv_conf);
555 if (rc)
556 goto leave;
557 }
558
559 for (i=0; reg_hotkeys[i].reg_entry; i++) {
560 strcpy (buf, " ");
561 if (reg_hotkeys[i].enabled)
562 strcpy (buf, reg_hotkeys[i].key);
563 rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG,
564 reg_hotkeys[i].reg_entry, buf);
565 if (rc)
566 break;
567 }
568
569 leave:
570 if (rc) {
571 msg_box (NULL, _("Could not write to Registry."), _("Preferences"), MB_ERR);
572 return rc;
573 }
574 return 0;
575 }
576
577
578 int
579 set_reg_winpt_flag (const char * name, int val)
580 {
581 return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0");
582 } /* set_reg_winpt_flag */
583
584
585 int
586 get_reg_winpt_flag (const char * name)
587 {
588 char * buf;
589 int flag = 0;
590
591 buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);
592 if (buf && buf[0] == '1')
593 flag = 1;
594 else if (!buf || buf && buf[0] != '0')
595 flag = -1;
596 free_if_alloc (buf);
597 return flag;
598 } /* get_reg_winpt_flag */
599
600
601 /* Retrieve the winpt preferences from the registry. */
602 int
603 get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
604 {
605 char * val = NULL;
606 size_t i;
607
608 for (i=1; i < DIM (cfg); i++) {
609 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);
610 if (!val || *val == ' ') {
611 free_if_alloc (val);
612 continue;
613 }
614 switch (i) {
615 case CFG_CACHETIME:
616 opt->cache_time = atol (val);
617 /* We do NOT support passphrase caching for more than an hour.
618 * Perhaps we should allow it, but for now we silently drop this.
619 */
620 if (opt->cache_time > 3600)
621 opt->cache_time = 3600;
622 break;
623 case CFG_WORDWRAP:
624 opt->word_wrap = atol (val);
625 break;
626 case CFG_FASTMODE:
627 opt->use_tmpfiles = atol (val);
628 break;
629 case CFG_NOZIP_MMEDIA:
630 opt->no_zip_mmedia = atol (val);
631 break;
632 case CFG_VIEWER:
633 opt->use_viewer = atol (val);
634 break;
635 case CFG_KEYLISTMODE:
636 opt->keylist_mode = atol (val);
637 break;
638 case CFG_WIPEMODE:
639 opt->wipe_mode = atol (val);
640 break;
641 case CFG_DISHOTKEYS:
642 opt->no_hotkeys = atol (val);
643 break;
644 case CFG_ALWAYSTRUST:
645 opt->always_trust = atol (val);
646 break;
647 case CFG_AUTOBACKUP:
648 opt->auto_backup = atol (val);
649 break;
650 case CFG_AUTOBAKMODE:
651 opt->backup.mode = atol (val);
652 break;
653 case CFG_EXPERT:
654 opt->expert = atol (val);
655 break;
656
657 case CFG_FM_PROGRESS:
658 opt->fm.progress = atol (val);
659 break;
660 }
661 free_if_alloc (val);
662 }
663
664 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath");
665 if (val && val[0] != ' ')
666 opt->backup.path = m_strdup (val);
667 free_if_alloc (val);
668
669 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig");
670 if (val && val[0] != ' ')
671 opt->kserv_conf = m_strdup (val);
672 free_if_alloc (val);
673
674 for (i=0; reg_hotkeys[i].reg_entry; i++) {
675 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);
676 if (val && val[0] != ' ') {
677 reg_hotkeys[i].key[0] = *val;
678 reg_hotkeys[i].enabled = 1;
679 }
680 else
681 reg_hotkeys[i].enabled = 0;
682 free_if_alloc (val);
683 }
684 return 0;
685 } /* get_reg_winpt_prefs */
686
687
688 char*
689 get_reg_entry_keyserver (const char *name)
690 {
691 char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name);
692 if (p && !strcmp (p, "")) {
693 free_if_alloc (p);
694 return NULL;
695 }
696 return p;
697 }
698
699
700 void
701 get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass)
702 {
703 if (host)
704 *host = get_reg_entry_keyserver ("Host");
705 if (user)
706 *user = get_reg_entry_keyserver ("User");
707 if (pass)
708 *pass = get_reg_entry_keyserver ("Pass");
709 if (port) {
710 char * p = get_reg_entry_keyserver ("Port");
711 if (p) {
712 *port = atol (p);
713 free_if_alloc (p);
714 }
715 }
716 } /* get_reg_proxy_prefs */
717
718
719 int
720 set_reg_entry_keyserver( const char * name, const char * val )
721 {
722 return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );
723 } /* set_reg_entry_keyserver */
724
725
726 int
727 set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass )
728 {
729 int rc;
730
731 rc = set_reg_entry_keyserver( "Host", host? host : "" );
732 if( !rc ) {
733 char buf[32];
734 sprintf( buf, "%d", port );
735 rc = set_reg_entry_keyserver( "Port", buf );
736 }
737 if( !rc )
738 rc = set_reg_entry_keyserver( "User", user? user : "" );
739 if( !rc )
740 rc = set_reg_entry_keyserver( "Pass", pass? pass : "" );
741 return rc;
742 } /* set_reg_proxy_prefs */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26