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

Diff of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.2  
changed lines
  Added in v.48

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26