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

Contents of /trunk/Src/wptOwnertrustDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 231 - (show annotations)
Tue Jun 20 09:18:44 2006 UTC (18 years, 8 months ago) by twoaday
File size: 3976 byte(s)
Some more patches and fixed typos.


1 /* wptOwnertrust.cpp - Ownertrust im- and export
2 * Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz
3 * Copyright (C) 2005 g10 Code GmbH
4 *
5 * This file is part of WinPT.
6 *
7 * WinPT is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * WinPT is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with WinPT; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <sys/stat.h>
27
28 #include "resource.h"
29 #include "wptTypes.h"
30 #include "wptGPG.h"
31 #include "wptErrors.h"
32 #include "wptNLS.h"
33 #include "wptW32API.h"
34
35
36 /* Export the ownertrust to the file @fname.
37 Return value: 0 on success. */
38 static gpgme_error_t
39 gpg_export_ownertrust (const char *fname)
40 {
41 gpgme_error_t err;
42 char *ot_data = NULL;
43 FILE *f;
44
45 err = gpg_manage_ownertrust (&ot_data, 1);
46 if (err)
47 return err;
48 f = fopen (fname, "wb");
49 if (f) {
50 fwrite (ot_data, 1, strlen (ot_data), f);
51 fclose (f);
52 }
53 else
54 err = gpg_error (GPG_ERR_ENOENT);
55 safe_free (ot_data);
56 return 0;
57 }
58
59
60 /* Import the ownertrust from file @fname.
61 Return value: 0 on success. */
62 static gpgme_error_t
63 gpg_import_ownertrust (const char *fname)
64 {
65 gpgme_error_t err;
66 FILE *f;
67 struct stat st;
68 char *ot_data;
69
70 if (stat (fname, &st))
71 return gpg_error (GPG_ERR_ENOENT);
72 f = fopen (fname, "rb");
73 if (!f)
74 return gpg_error (GPG_ERR_ENOENT);
75 ot_data = (char*)calloc (1, st.st_size+1);
76 if (!ot_data)
77 BUG (NULL);
78 fread (ot_data, 1, st.st_size, f);
79 fclose (f);
80
81 err = gpg_manage_ownertrust (&ot_data, 0);
82
83 safe_free (ot_data);
84 return 0;
85 }
86
87
88 /* Dialog procedure to manage the ownertrust. */
89 BOOL CALLBACK
90 ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
91 {
92 gpgme_error_t err;
93 const char *fname;
94
95 switch( msg ) {
96 case WM_INITDIALOG:
97 SetWindowText (dlg, _("Ownertrust"));
98 SetDlgItemText (dlg, IDC_OWNERTRUST_INFO, _("File"));
99 SetDlgItemText (dlg, IDC_OWNERTRUST_DESC,
100 _("Here it is possible to save or restore the ownertrust from the "
101 "'trustdb' file. This could be very useful because the values are NOT "
102 "stored in the keyring."));
103 SetDlgItemText (dlg, IDCANCEL, _("&Close"));
104 center_window (dlg, NULL);
105 SetForegroundWindow (dlg);
106 return TRUE;
107
108 case WM_COMMAND:
109 switch (LOWORD (wparam)) {
110 case IDC_OWNERTRUST_EXPORT:
111 fname = get_filesave_dlg (dlg, _("Select File Name for Output"), NULL, NULL);
112 if (!fname)
113 return TRUE;
114 err = gpg_export_ownertrust (fname);
115 if (err) {
116 msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
117 return TRUE;
118 }
119 status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
120 return TRUE;
121
122 case IDC_OWNERTRUST_IMPORT:
123 fname = get_fileopen_dlg (dlg, _("Select File Name for Input"), NULL, NULL);
124 if (!fname)
125 return TRUE;
126 err = gpg_import_ownertrust (fname);
127 if (err) {
128 msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
129 return TRUE;
130 }
131 status_box (dlg, _("Ownertrust successfully imported."), _("GnuPG Status"));
132 return TRUE;
133
134 case IDCANCEL:
135 EndDialog (dlg, FALSE);
136 return TRUE;
137 }
138 break;
139 }
140
141 return FALSE;
142 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26