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

Annotation of /trunk/Src/wptOwnertrustDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 4204 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

1 twoaday 2 /* wptOwnertrust.cpp - Ownertrust im- and export
2 twoaday 23 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3     * Copyright (C) 2005 g10 Code GmbH
4 twoaday 2 *
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    
22     #include <windows.h>
23 twoaday 23 #include <errno.h>
24     #include <sys/stat.h>
25 twoaday 2
26     #include "../resource.h"
27     #include "wptTypes.h"
28     #include "wptGPG.h"
29     #include "wptErrors.h"
30     #include "wptNLS.h"
31     #include "wptW32API.h"
32    
33    
34 twoaday 23 /* Export the ownertrust to the file @fname.
35     Return value: 0 on success. */
36     static gpgme_error_t
37     gpg_export_ownertrust (const char *fname)
38     {
39     gpgme_error_t err;
40     char *ot_data = NULL;
41     FILE *f;
42    
43     err = gpg_manage_ownertrust (&ot_data, 1);
44     if (err)
45     return err;
46     f = fopen (fname, "wb");
47     if (f) {
48     fwrite (ot_data, 1, strlen (ot_data), f);
49     fclose (f);
50     }
51     else
52     err = gpg_error_from_errno (errno);
53     free (ot_data);
54     return 0;
55     }
56    
57    
58     /* Import the ownertrust from file @fname.
59     Return value: 0 on success. */
60     static gpgme_error_t
61     gpg_import_ownertrust (const char *fname)
62     {
63     gpgme_error_t err;
64     FILE *f;
65     struct stat st;
66     char *ot_data;
67    
68     if (stat (fname, &st))
69     return gpg_error_from_errno (errno);
70     f = fopen (fname, "rb");
71     if (!f)
72     return gpg_error_from_errno (errno);
73     ot_data = (char*)calloc (1, st.st_size+1);
74     if (!ot_data)
75     BUG (NULL);
76     fread (ot_data, 1, st.st_size, f);
77     fclose (f);
78    
79     err = gpg_manage_ownertrust (&ot_data, 0);
80    
81     free (ot_data);
82     return 0;
83     }
84    
85    
86     /* Dialog procedure to manage the ownertrust. */
87 twoaday 2 BOOL CALLBACK
88 twoaday 23 ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
89 twoaday 2 {
90     gpgme_error_t err;
91 twoaday 25 const char *fname;
92 twoaday 2
93     switch( msg ) {
94     case WM_INITDIALOG:
95 twoaday 23 #ifndef LANG_DE
96 twoaday 2 SetWindowText( dlg, _("Ownertrust") );
97     SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );
98     SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,
99     _("Here it is possible to save or restore the ownertrust from the "
100     "'trustdb' file. This could be very useful because the values are NOT "
101     "stored in the keyring.") );
102 twoaday 23 #endif
103     center_window( dlg, NULL );
104 twoaday 2 SetForegroundWindow( dlg );
105     return TRUE;
106    
107     case WM_SYSCOMMAND:
108 twoaday 25 if (LOWORD (wparam) == SC_CLOSE)
109     EndDialog (dlg, TRUE);
110     return TRUE;
111 twoaday 2
112     case WM_COMMAND:
113 twoaday 25 switch (LOWORD (wparam)) {
114 twoaday 2 case IDC_OWNERTRUST_EXPORT:
115 twoaday 25 fname = get_filesave_dlg (dlg, _("Select file name for output"), NULL, NULL);
116     if (!fname)
117     return TRUE;
118 twoaday 23 err = gpg_export_ownertrust (fname);
119 twoaday 25 if (err) {
120     msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
121     return TRUE;
122 twoaday 2 }
123 twoaday 25 status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
124 twoaday 2 return TRUE;
125    
126     case IDC_OWNERTRUST_IMPORT:
127 twoaday 25 fname = get_fileopen_dlg (dlg, _("Select file name for input"), NULL, NULL);
128     if (!fname)
129     return TRUE;
130     err = gpg_import_ownertrust (fname);
131     if (err) {
132     msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
133     return TRUE;
134 twoaday 2 }
135 twoaday 25 status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));
136 twoaday 2 return TRUE;
137    
138     case IDCANCEL:
139 twoaday 25 EndDialog (dlg, FALSE);
140     return TRUE;
141 twoaday 2 }
142     break;
143     }
144    
145     return FALSE;
146 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26