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

Contents of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 180 - (show annotations)
Mon Mar 6 14:41:58 2006 UTC (18 years, 11 months ago) by twoaday
File size: 17971 byte(s)
2006-02-27  Timo Schulz  <twoaday@freakmail.de>
 
        * wptSOCKS.cpp (socks_handshake): New.
        * wptMainProc.cpp (winpt_main_proc): A dbl-click forces
        the key manager in teh foreground if possible.
        * wptHotkey.cpp (hotkey_unregister): Unregister all hotkeys.
        * wptRegistry.cpp (get_reg_proxy_prefs,
        set_reg_proxy_prefs): Use directly the proxy context.
        Changed all callers.
        * wptProxySettingsDlg.cpp (init_proxy_protocols): New.
        (keyserver_proxy_dlg_proc): Use directly the proxy context.
        * wptKeyserver.cpp (kserver_connect): Better proxy support.
        (kserver_send_request, kserver_recvkey_request): Likewise.
        * wptKeyserverDlg.cpp (name_from_proto): New.
        (set_proxy): Adjusted for the new code.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26