/[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 213 by twoaday, Thu May 11 13:32:56 2006 UTC revision 271 by twoaday, Sun Nov 5 08:57:45 2006 UTC
# Line 1  Line 1 
1  /* wptFileStatDlg.cpp - (File Manager) Show file statistics  /* wptFileStatDlg.cpp - List the status of an OpenPGP file
2   *      Copyright (C) 2002, 2003, 2005 Timo Schulz   *      Copyright (C) 2002, 2003, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 27  Line 27 
27    
28  #include "resource.h"  #include "resource.h"
29  #include "wptTypes.h"  #include "wptTypes.h"
 #include "wptNLS.h"  
30  #include "wptGPG.h"  #include "wptGPG.h"
31  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
32  #include "wptContext.h"  #include "wptContext.h"
 #include "wptDlgs.h"  
33  #include "wptErrors.h"  #include "wptErrors.h"
34  #include "wptW32API.h"  #include "wptW32API.h"
35    #include "wptUTF8.h"
36  #include "openpgp.h"  #include "openpgp.h"
37    
38    /* Make sure that the list won't consume too much memory. */
39    #define MAX_PKTS 1024
40    
41    /* Return the date in locale format. */
42    const char*
43    get_fmt_date (long timest)
44    {
45        static char buf[64];
46    
47        get_locale_date (timest, buf, DIM (buf)-1);
48        return buf;
49    }
50    
51    
52    /* Return humand readable public key algo. */
53  static const char*  static const char*
54  get_pubkey_algo (int algo)  get_pubkey_algo (int algo)
55  {        {      
# Line 49  get_pubkey_algo (int algo) Line 63  get_pubkey_algo (int algo)
63  }  }
64    
65    
66    /* Return human readable symmetric algo. */
67  const char*  const char*
68  get_symkey_algo (int algo)  get_symkey_algo (int algo)
69  {  {
# Line 58  get_symkey_algo (int algo) Line 73  get_symkey_algo (int algo)
73      case 2: return "3DES";      case 2: return "3DES";
74      case 3: return "CAST5";      case 3: return "CAST5";
75      case 4: return "BLOWFISH";      case 4: return "BLOWFISH";
76      case 5: return "RESERVED";      case 7: return "AES128";
77      case 6: return "RESERVED";      case 8: return "AES192";
78      case 7: return "AES";      case 9: return "AES256";
     case 8: return "AES-192";  
     case 9: return "AES-256";  
79      default: break;      default: break;
80      }          }    
81      return "UNKNOWN";      return "UNKNOWN";
82  }  }
83    
84    
85    /* Return human readable hash algo. */
86  static const char*  static const char*
87  get_digest_algo (int algo)  get_digest_algo (int algo)
88  {  {
# Line 77  get_digest_algo (int algo) Line 91  get_digest_algo (int algo)
91      case 1: return "MD5";      case 1: return "MD5";
92      case 2: return "SHA1";      case 2: return "SHA1";
93      case 3: return "RMD160";      case 3: return "RMD160";
     case 4: return "RESERVED";  
94      case 5: return "MD2";      case 5: return "MD2";
     case 6: return "RESERVED";  
     case 7: return "RESERVED";  
95      case 8: return "SHA256";      case 8: return "SHA256";
96      case 9: return "SHA384";      case 9: return "SHA384";
97      case 10:return "SHA512";      case 10:return "SHA512";
# Line 90  get_digest_algo (int algo) Line 101  get_digest_algo (int algo)
101  }  }
102    
103    
104    /* Return human readable compress algo. */
105  static const char*  static const char*
106  get_compress_algo (int algo)  get_compress_algo (int algo)
107  {  {
# Line 104  get_compress_algo (int algo) Line 116  get_compress_algo (int algo)
116  }  }
117    
118    
119    /* Return human string to key algo. */
120  static const char*  static const char*
121  get_s2k_algo (int algo)  get_s2k_algo (int algo)
122  {  {
# Line 117  get_s2k_algo (int algo) Line 130  get_s2k_algo (int algo)
130  }  }
131    
132    
133  static const char*  /* List all OpenPGP packets from the file @file.
 get_timestring (long timestamp)  
 {  
     static char ts[64];  
     struct tm *ltm;  
   
     ltm = localtime (&timestamp);  
     _snprintf(ts, sizeof ts -1, "%04d-%02d-%02d",  
                 ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday);  
     return ts;  
 }  
   
   
 /* List all PGP packets from the file @file.  
134     Return value: number of packets. */     Return value: number of packets. */
135  static int  static int
136  do_list_packets (HWND list, const char *file)  do_list_packets (HWND list, const char *file)
# Line 140  do_list_packets (HWND list, const char * Line 140  do_list_packets (HWND list, const char *
140      armor_filter_context_t afx;      armor_filter_context_t afx;
141      size_t n=0;      size_t n=0;
142      int rc = 0;      int rc = 0;
143      char inf[1024];      char inf[1024], *p;
144    
145      if (!list || !file) {      if (!list || !file) {
146          log_debug ("do_list_packets: !list || !file");          log_debug ("do_list_packets: invalid parameters\n");
147          return -1;          return -1;
148      }      }
149    
150      inp = gpg_iobuf_open (file);      inp = gpg_iobuf_open (file);
151      if (!inp) {      if (!inp) {
152          log_box (_("File Manager"), MB_ERR, "%s: %s", file,          log_box (_("File Manager"), MB_ERR, "%s: %s", file,
153                   winpt_strerror (WPTERR_FILE_OPEN));                   winpt_strerror (WPTERR_FILE_OPEN));
154          return -1;          return -1;
155      }      }
156      gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */
157      if (gpg_use_armor_filter (inp)) {      if (gpg_use_armor_filter (inp)) {
158          memset (&afx, 0, sizeof (afx));          memset (&afx, 0, sizeof (afx));
159          gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);          gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);
# Line 166  do_list_packets (HWND list, const char * Line 166  do_list_packets (HWND list, const char *
166              {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;              {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;
167              if (!enc)              if (!enc)
168                  break;                  break;
169              _snprintf( inf, sizeof(inf)-1,                    _snprintf (inf, DIM(inf)-1,
170                  "public key encryted packet: version %d, algo %s, keyid 0x%08X",                  "public key encryted packet: version %d, algo %s, keyid 0x%08X",
171                  enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);                  enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);
172              listbox_add_string (list, inf);}              listbox_add_string (list, inf);}
# Line 176  do_list_packets (HWND list, const char * Line 176  do_list_packets (HWND list, const char *
176              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
177              if (!enc)              if (!enc)
178                  break;                  break;
179              _snprintf (inf, sizeof(inf)-1,              _snprintf (inf, DIM(inf)-1,
180                  "symmetric key encrypted packet: version %d, cipher %s, s2k %s, hash %s",                  "symmetric key encrypted packet: version %d, cipher %s, s2k %s, hash %s",
181                  enc->version, get_symkey_algo(enc->cipher_algo),                                  enc->version, get_symkey_algo (enc->cipher_algo),
182                  get_s2k_algo (enc->s2k.mode), get_digest_algo(enc->s2k.hash_algo));                  get_s2k_algo (enc->s2k.mode),
183                    get_digest_algo (enc->s2k.hash_algo));
184              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
185              break;              break;
186    
# Line 188  do_list_packets (HWND list, const char * Line 189  do_list_packets (HWND list, const char *
189              {PKT_encrypted *enc = pkt->pkt.encrypted; n++;              {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
190              if (!enc)              if (!enc)
191                  break;                  break;
192              _snprintf( inf, sizeof(inf)-1,                    _snprintf (inf, DIM(inf)-1,
193                  "encrypted data packet: mdc method %d, length %d",                                        "encrypted data packet: mdc method %d, length %d",
194                  enc->mdc_method, enc->len );                          enc->mdc_method, enc->len);
195              listbox_add_string( list, inf ); }              listbox_add_string (list, inf); }
196              break;              break;
197    
198          case PKT_PUBLIC_KEY:          case PKT_PUBLIC_KEY:
# Line 199  do_list_packets (HWND list, const char * Line 200  do_list_packets (HWND list, const char *
200              {PKT_public_key *pk = pkt->pkt.public_key; n++;              {PKT_public_key *pk = pkt->pkt.public_key; n++;
201              if (!pk)              if (!pk)
202                  break;                  break;
203              _snprintf( inf, sizeof(inf)-1,              _snprintf( inf, DIM(inf)-1,
204                  "public key packet: version %d, algo %s, created %s",                  "public key packet: version %d, algo %s, created %s",
205                  pk->version, get_pubkey_algo(pk->pubkey_algo),                  pk->version, get_pubkey_algo (pk->pubkey_algo),
206                  get_timestring(pk->timestamp));                  get_fmt_date (pk->timestamp));
207              listbox_add_string( list, inf ); }              listbox_add_string (list, inf); }
208              break;              break;
209    
210          case PKT_SECRET_KEY:          case PKT_SECRET_KEY:
# Line 211  do_list_packets (HWND list, const char * Line 212  do_list_packets (HWND list, const char *
212              {PKT_secret_key *sk = pkt->pkt.secret_key; n++;              {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
213              if (!sk)              if (!sk)
214                  break;                  break;
215              _snprintf( inf, sizeof(inf)-1,              _snprintf( inf, DIM(inf)-1,
216                  "secret key packet: version %d, algo %s, created %s mode %d",                  "secret key packet: version %d, algo %s, created %s mode %d",
217                  sk->version,  get_pubkey_algo( sk->pubkey_algo ),                  sk->version,  get_pubkey_algo (sk->pubkey_algo),
218                  get_timestring( sk->timestamp ),                  get_fmt_date (sk->timestamp),
219                  sk->protect.s2k.mode );                  sk->protect.s2k.mode);
220              listbox_add_string( list, inf ); }              listbox_add_string (list, inf); }
221              break;              break;
222                
                   
223          case PKT_SIGNATURE:          case PKT_SIGNATURE:
224              {PKT_signature *sig = pkt->pkt.signature; n++;              {PKT_signature *sig = pkt->pkt.signature; n++;
225              if (!sig)              if (!sig)
226                  break;                  break;
227              _snprintf( inf, sizeof(inf)-1,              _snprintf( inf, DIM(inf)-1,
228                  "signature packet: version %d, algo %s, keyid 0x%08X, created %s",                  "signature packet: version %d, algo %s, keyid 0x%08X, created %s",
229                  sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],                  sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],
230                  get_timestring(sig->timestamp));                  get_fmt_date (sig->timestamp));
231              listbox_add_string( list, inf ); }              listbox_add_string (list, inf); }
232              break;              break;
233    
234                                    
# Line 236  do_list_packets (HWND list, const char * Line 236  do_list_packets (HWND list, const char *
236              {PKT_user_id *id = pkt->pkt.user_id; n++;              {PKT_user_id *id = pkt->pkt.user_id; n++;
237              if (!id)              if (!id)
238                  break;                  break;
239              _snprintf( inf, sizeof(inf)-1, "user id packet: %s", id->name );              p = utf8_to_native (id->name);
240              listbox_add_string( list, inf ); }              _snprintf (inf, DIM (inf)-1, "user id packet: %s", p);
241                free_if_alloc (p);
242                listbox_add_string (list, inf); }
243              break;              break;
244                            
245          case PKT_COMPRESSED:          case PKT_COMPRESSED:
246              {PKT_compressed *zip = pkt->pkt.compressed; n++;              {PKT_compressed *zip = pkt->pkt.compressed; n++;
247              if (!zip)              if (!zip)
248                  break;                  break;
249              _snprintf( inf, sizeof(inf)-1, "compressed packet: algo %s, length %d",              _snprintf (inf, DIM(inf)-1,
250                  get_compress_algo(zip->algorithm), zip->len );                          "compressed packet: algo %s, length %d",
251              listbox_add_string( list, inf ); }                          get_compress_algo(zip->algorithm), zip->len);
252                listbox_add_string (list, inf); }
253              break;              break;
254    
255          default:          default:
# Line 254  do_list_packets (HWND list, const char * Line 257  do_list_packets (HWND list, const char *
257          }          }
258          gpg_free_packet (pkt);          gpg_free_packet (pkt);
259          gpg_init_packet (pkt);          gpg_init_packet (pkt);
260            if (n > MAX_PKTS)
261                break;
262      }      }
263      gpg_iobuf_close (inp);      gpg_iobuf_close (inp);
264      safe_free (pkt);      safe_free (pkt);
# Line 266  BOOL CALLBACK Line 271  BOOL CALLBACK
271  file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
272  {  {
273      const char *file;      const char *file;
     int n;  
274            
275      switch (msg) {      switch (msg) {
276      case WM_INITDIALOG:      case WM_INITDIALOG:        
         #ifndef LANG_DE  
         SetWindowText (dlg, _("File Status"));  
         #endif  
277          file = (const char*)lparam;          file = (const char*)lparam;
278          if (file == NULL)          if (!file)
279              dlg_fatal_error( dlg, "Could not get dialog state!" );              BUG (0);
280          n = do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file);          if (do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file) < 1) {
281          if (n < 1) {              msg_box (dlg, _("No valid OpenPGP data found."),
282              msg_box (dlg, _("No valid OpenPGP data found."), _("File Status"), MB_ERR);                       _("File Status"), MB_ERR);
283              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
284                return TRUE;
285          }          }
286            SetWindowText (dlg, _("File Status"));
287          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
288          break;          break;
289                    
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
         return TRUE;  
           
290      case WM_COMMAND:      case WM_COMMAND:
291          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
292          case IDOK:          case IDOK:

Legend:
Removed from v.213  
changed lines
  Added in v.271

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26