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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 7249 byte(s)
Minor changes; compiles now but gettext is still missing.

1 werner 36 /* wptFileStatDlg.cpp - (File Manager) Show file statistics
2     * Copyright (C) 2002, 2003, 2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (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
14     * GNU 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 <windows.h>
27     #include <time.h>
28     #include <sys/types.h>
29    
30 werner 47 #include "resource.h"
31 werner 36 #include "wptTypes.h"
32     #include "wptNLS.h"
33     #include "wptGPG.h"
34     #include "wptCommonCtl.h"
35     #include "wptContext.h"
36     #include "wptDlgs.h"
37     #include "wptErrors.h"
38     #include "wptW32API.h"
39     #include "openpgp.h"
40    
41     static const char*
42     get_pubkey_algo (int algo)
43     {
44     if (algo == 17)
45     return "DSA";
46     else if (is_ELGAMAL (algo))
47     return "ELG";
48     else if (is_RSA (algo))
49     return "RSA";
50     return NULL;
51     }
52    
53    
54     const char*
55     get_symkey_algo (int algo)
56     {
57     switch (algo) {
58     case 0: return "PLAINTEXT";
59     case 1: return "IDEA";
60     case 2: return "3DES";
61     case 3: return "CAST5";
62     case 4: return "BLOWFISH";
63     case 5: return "RESERVED";
64     case 6: return "RESERVED";
65     case 7: return "AES";
66     case 8: return "AES-192";
67     case 9: return "AES-256";
68     }
69     return "UNKNOWN";
70     }
71    
72    
73     static const char*
74     get_digest_algo (int algo)
75     {
76     switch (algo) {
77     case 0: return "NONE";
78     case 1: return "MD5";
79     case 2: return "SHA1";
80     case 3: return "RMD160";
81     case 4: return "RESERVED";
82     case 5: return "MD2";
83     case 6: return "RESERVED";
84     case 7: return "RESERVED";
85     case 8: return "SHA256";
86     case 9: return "SHA384";
87     case 10:return "SHA512";
88     }
89     return "UNKNOWN";
90     }
91    
92    
93     static const char*
94     get_compress_algo (int algo)
95     {
96     switch (algo) {
97     case 0: return "NONE";
98     case 1: return "ZIB";
99     case 2: return "ZLIB";
100     case 3: return "BZIP2";
101     }
102     return "UNKNOWN";
103     }
104    
105    
106     static const char*
107     get_timestring (long timestamp)
108     {
109     static char ts[64];
110     struct tm *ltm;
111    
112     ltm = localtime (&timestamp);
113     _snprintf(ts, sizeof ts -1, "%04d-%02d-%02d",
114     ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday);
115     return ts;
116     }
117    
118    
119     /* List all PGP packets from the file @file.
120     Return value: number of packets. */
121     static int
122     do_list_packets (HWND list, const char *file)
123     {
124     PACKET *pkt;
125     gpg_iobuf_t inp = NULL;
126     armor_filter_context_t afx;
127     size_t n=0;
128     int rc = 0;
129     char inf[1024];
130    
131     if (!list || !file) {
132     log_debug ("do_list_packets: !list || !file");
133     return -1;
134     }
135    
136     inp = gpg_iobuf_open (file);
137     if (!inp) {
138     log_box (_("File Manager"), MB_ERR, "%s: %s", file,
139     winpt_strerror (WPTERR_FILE_OPEN));
140     return -1;
141     }
142     gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */
143     if (gpg_use_armor_filter (inp)) {
144     memset (&afx, 0, sizeof (afx));
145     gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);
146     }
147     pkt = (PACKET *)calloc(1, sizeof *pkt);
148     gpg_init_packet (pkt);
149     while ((rc = gpg_parse_packet (inp, pkt)) != -1) {
150     switch (pkt->pkttype) {
151     case PKT_PUBKEY_ENC:
152     {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;
153     if (!enc)
154     break;
155     _snprintf( inf, sizeof(inf)-1,
156     "public key encryted packet: version %d, algo %s, keyid 0x%08X",
157     enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);
158     listbox_add_string (list, inf);}
159     break;
160    
161     case PKT_SYMKEY_ENC:
162     {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
163     if (!enc)
164     break;
165     _snprintf( inf, sizeof(inf)-1,
166     "symmetric key encrypted packet: version %d, cipher %s, s2k %d, hash %s",
167     enc->version, get_symkey_algo(enc->cipher_algo),
168     enc->s2k.mode, get_digest_algo(enc->s2k.hash_algo) );
169     listbox_add_string( list, inf ); }
170     break;
171    
172     case PKT_ENCRYPTED:
173     case PKT_ENCRYPTED_MDC:
174     {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
175     if (!enc)
176     break;
177     _snprintf( inf, sizeof(inf)-1,
178     "encrypted data packet: mdc method %d, length %d",
179     enc->mdc_method, enc->len );
180     listbox_add_string( list, inf ); }
181     break;
182    
183     case PKT_PUBLIC_KEY:
184     case PKT_PUBLIC_SUBKEY:
185     {PKT_public_key *pk = pkt->pkt.public_key; n++;
186     if (!pk)
187     break;
188     _snprintf( inf, sizeof(inf)-1,
189     "public key packet: version %d, algo %s, created %s",
190     pk->version, get_pubkey_algo(pk->pubkey_algo),
191     get_timestring(pk->timestamp));
192     listbox_add_string( list, inf ); }
193     break;
194    
195     case PKT_SECRET_KEY:
196     case PKT_SECRET_SUBKEY:
197     {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
198     if (!sk)
199     break;
200     _snprintf( inf, sizeof(inf)-1,
201     "secret key packet: version %d, algo %s, created %s mode %d",
202     sk->version, get_pubkey_algo( sk->pubkey_algo ),
203     get_timestring( sk->timestamp ),
204     sk->protect.s2k.mode );
205     listbox_add_string( list, inf ); }
206     break;
207    
208    
209     case PKT_SIGNATURE:
210     {PKT_signature *sig = pkt->pkt.signature; n++;
211     if (!sig)
212     break;
213     _snprintf( inf, sizeof(inf)-1,
214     "signature packet: version %d, algo %s, keyid 0x%08X, created %s",
215     sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],
216     get_timestring(sig->timestamp));
217     listbox_add_string( list, inf ); }
218     break;
219    
220    
221     case PKT_USER_ID:
222     {PKT_user_id *id = pkt->pkt.user_id; n++;
223     if (!id)
224     break;
225     _snprintf( inf, sizeof(inf)-1, "user id packet: %s", id->name );
226     listbox_add_string( list, inf ); }
227     break;
228    
229     case PKT_COMPRESSED:
230     {PKT_compressed *zip = pkt->pkt.compressed; n++;
231     if (!zip)
232     break;
233     _snprintf( inf, sizeof(inf)-1, "compressed packet: algo %s, length %d",
234     get_compress_algo(zip->algorithm), zip->len );
235     listbox_add_string( list, inf ); }
236     break;
237     }
238     gpg_free_packet (pkt);
239     gpg_init_packet (pkt);
240     }
241     gpg_iobuf_close (inp);
242     safe_free (pkt);
243     return n;
244     }
245    
246    
247     /* Dialog box procedure for showing file status. */
248     BOOL CALLBACK
249     file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
250     {
251     const char *file;
252     int n;
253    
254     switch (msg) {
255     case WM_INITDIALOG:
256     #ifndef LANG_DE
257     SetWindowText (dlg, _("File Status"));
258     #endif
259     file = (const char*)lparam;
260     if (file == NULL)
261     dlg_fatal_error( dlg, "Could not get dialog state!" );
262     n = do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file);
263     if (n < 1) {
264     msg_box (dlg, _("No valid OpenPGP data found."), _("File Status"), MB_ERR);
265     EndDialog (dlg, FALSE);
266     }
267     SetForegroundWindow (dlg);
268     break;
269    
270     case WM_SYSCOMMAND:
271     if (LOWORD (wparam) == SC_CLOSE)
272     EndDialog (dlg, TRUE);
273     return TRUE;
274    
275     case WM_COMMAND:
276     switch (LOWORD (wparam)) {
277     case IDOK:
278     EndDialog (dlg, TRUE);
279     break;
280     }
281     break;
282     }
283    
284     return FALSE;
285     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26