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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 7235 byte(s)
WinPT initial checkin.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26