/[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 327 by twoaday, Sat Apr 7 11:07:20 2007 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 1  Line 1 
1  /* wptFileStatDlg.cpp - List the status of an OpenPGP file  /* wptFileStatDlg.cpp - List the status of an OpenPGP file
2   *      Copyright (C) 2002, 2003, 2005, 2006 Timo Schulz   *      Copyright (C) 2002-2003, 2005-2006, 2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
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.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 36  Line 32 
32  #include "wptUTF8.h"  #include "wptUTF8.h"
33  #include "openpgp.h"  #include "openpgp.h"
34    
35    
36  /* Make sure that the list won't consume too much memory. */  /* Make sure that the list won't consume too much memory. */
37  #define MAX_PKTS 1024  #define MAX_PKTS 1024
38    
 /* Return the date in locale format. */  
 const char*  
 get_fmt_date (long timest)  
 {  
     static char buf[128];  
   
     get_locale_date (timest, buf, DIM (buf)-1);  
     return buf;  
 }  
   
   
39  /* Return humand readable public key algo. */  /* Return humand readable public key algo. */
40  static const char*  static const char*
41  get_pubkey_algo (int algo)  get_pubkey_algo (int algo)
# Line 96  get_digest_algo (int algo) Line 82  get_digest_algo (int algo)
82      case 8: return "SHA256";      case 8: return "SHA256";
83      case 9: return "SHA384";      case 9: return "SHA384";
84      case 10:return "SHA512";      case 10:return "SHA512";
85        case 11:return "SHA224";
86      default: break;      default: break;
87      }      }
88      return "UNKNOWN";      return "UNKNOWN";
# Line 139  do_list_packets (HWND list, const char * Line 126  do_list_packets (HWND list, const char *
126      PACKET *pkt;      PACKET *pkt;
127      gpg_iobuf_t inp = NULL;      gpg_iobuf_t inp = NULL;
128      armor_filter_context_t afx;      armor_filter_context_t afx;
     size_t n=0;  
     int rc = 0;  
129      char inf[1024], *p;      char inf[1024], *p;
130        char fmtdate[128];
131        size_t n;
132        int rc;    
133    
134      if (!list || !file) {      if (!list || !file) {
135          log_debug ("do_list_packets: invalid parameters\n");          log_debug ("do_list_packets: invalid parameters\n");
# Line 161  do_list_packets (HWND list, const char * Line 149  do_list_packets (HWND list, const char *
149      }      }
150      pkt = (PACKET *)calloc(1, sizeof *pkt);      pkt = (PACKET *)calloc(1, sizeof *pkt);
151      gpg_init_packet (pkt);      gpg_init_packet (pkt);
152        n=0;
153      while ((rc = gpg_parse_packet (inp, pkt)) != -1) {      while ((rc = gpg_parse_packet (inp, pkt)) != -1) {
154          switch (pkt->pkttype) {          switch (pkt->pkttype) {
155          case PKT_PUBKEY_ENC:          case PKT_PUBKEY_ENC:
# Line 168  do_list_packets (HWND list, const char * Line 157  do_list_packets (HWND list, const char *
157              if (!enc)              if (!enc)
158                  break;                  break;
159              _snprintf (inf, DIM(inf)-1,              _snprintf (inf, DIM(inf)-1,
160                  "public key encryted packet: version %d, algo %s, keyid 0x%08X",                         "public key encryted packet: "
161                  enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);                         "version %d, algo %s, keyid 0x%08X",
162                           enc->version, get_pubkey_algo(enc->pubkey_algo),
163                           enc->keyid[1]);
164              listbox_add_string (list, inf);}              listbox_add_string (list, inf);}
165              break;              break;
166                                    
167          case PKT_SYMKEY_ENC:          case PKT_SYMKEY_ENC:
168              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
169              if (!enc)                  if (!enc)
170                  break;                  break;
171              _snprintf (inf, DIM(inf)-1,              _snprintf (inf, DIM(inf)-1,
172                  "symmetric key encrypted packet: version %d, cipher %s, s2k %s, hash %s",                         "symmetric key encrypted packet: "
173                  enc->version, get_symkey_algo (enc->cipher_algo),                         "version %d, cipher %s, s2k %s, hash %s",
174                  get_s2k_algo (enc->s2k.mode),                         enc->version, get_symkey_algo (enc->cipher_algo),
175                  get_digest_algo (enc->s2k.hash_algo));                         get_s2k_algo (enc->s2k.mode),
176                           get_digest_algo (enc->s2k.hash_algo));
177              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
178              break;              break;
179    
# Line 190  do_list_packets (HWND list, const char * Line 182  do_list_packets (HWND list, const char *
182              {PKT_encrypted *enc = pkt->pkt.encrypted; n++;              {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
183              if (!enc)              if (!enc)
184                  break;                  break;
185              _snprintf (inf, DIM(inf)-1,              _snprintf (inf, DIM (inf)-1,        
186                          "encrypted data packet: mdc method %d, length %d",                         "encrypted data packet: mdc method %d, length %d",
187                          enc->mdc_method, enc->len);                         enc->mdc_method, enc->len);
188              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
189              break;              break;
190    
# Line 201  do_list_packets (HWND list, const char * Line 193  do_list_packets (HWND list, const char *
193              {PKT_public_key *pk = pkt->pkt.public_key; n++;              {PKT_public_key *pk = pkt->pkt.public_key; n++;
194              if (!pk)              if (!pk)
195                  break;                  break;
196              _snprintf( inf, DIM(inf)-1,              _snprintf (inf, DIM(inf)-1,
197                  "public key packet: version %d, algo %s, created %s",                         "public key packet: version %d, algo %s, created %s",
198                  pk->version, get_pubkey_algo (pk->pubkey_algo),                         pk->version, get_pubkey_algo (pk->pubkey_algo),
199                  get_fmt_date (pk->timestamp));                         get_locale_date (pk->timestamp, fmtdate,
200                                            DIM (fmtdate)-1));
201              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
202              break;              break;
203    
# Line 213  do_list_packets (HWND list, const char * Line 206  do_list_packets (HWND list, const char *
206              {PKT_secret_key *sk = pkt->pkt.secret_key; n++;              {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
207              if (!sk)              if (!sk)
208                  break;                  break;
209              _snprintf( inf, DIM(inf)-1,              _snprintf (inf, DIM (inf)-1,
210                  "secret key packet: version %d, algo %s, created %s mode %d",                         "secret key packet: "
211                  sk->version,  get_pubkey_algo (sk->pubkey_algo),                         "version %d, algo %s, created %s mode %d",
212                  get_fmt_date (sk->timestamp),                         sk->version,  get_pubkey_algo (sk->pubkey_algo),
213                  sk->protect.s2k.mode);                         get_locale_date (sk->timestamp, fmtdate,
214                                            DIM(fmtdate)-1),
215                           sk->protect.s2k.mode);
216              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
217              break;              break;
218                            
# Line 225  do_list_packets (HWND list, const char * Line 220  do_list_packets (HWND list, const char *
220              {PKT_signature *sig = pkt->pkt.signature; n++;              {PKT_signature *sig = pkt->pkt.signature; n++;
221              if (!sig)              if (!sig)
222                  break;                  break;
223              _snprintf( inf, DIM(inf)-1,              _snprintf (inf, DIM(inf)-1,
224                  "signature packet: version %d, algo %s, keyid 0x%08X, created %s",                         "signature packet: "
225                  sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],                         "version %d, algo %s, keyid 0x%08X, created %s",
226                  get_fmt_date (sig->timestamp));                         sig->version, get_pubkey_algo(sig->pubkey_algo),
227                           sig->keyid[1],
228                           get_locale_date (sig->timestamp, fmtdate,
229                                            DIM(fmtdate)-1));
230              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
231              break;              break;
232    
# Line 247  do_list_packets (HWND list, const char * Line 245  do_list_packets (HWND list, const char *
245              {PKT_compressed *zip = pkt->pkt.compressed; n++;              {PKT_compressed *zip = pkt->pkt.compressed; n++;
246              if (!zip)              if (!zip)
247                  break;                  break;
248              _snprintf (inf, DIM(inf)-1,              _snprintf (inf, DIM (inf)-1,
249                          "compressed packet: algo %s, length %d",                         "compressed packet: algo %s, length %d",
250                          get_compress_algo(zip->algorithm), zip->len);                         get_compress_algo(zip->algorithm), zip->len);
251              listbox_add_string (list, inf); }              listbox_add_string (list, inf); }
252              break;              break;
253    
# Line 258  do_list_packets (HWND list, const char * Line 256  do_list_packets (HWND list, const char *
256          }          }
257          gpg_free_packet (pkt);          gpg_free_packet (pkt);
258          gpg_init_packet (pkt);          gpg_init_packet (pkt);
259          if (n > MAX_PKTS)          if (n > MAX_PKTS) {
260                listbox_add_string(list, "--last shown packet--");
261              break;              break;
262            }
263      }      }
264      gpg_iobuf_close (inp);      gpg_iobuf_close (inp);
265      safe_free (pkt);      safe_free (pkt);
# Line 271  do_list_packets (HWND list, const char * Line 271  do_list_packets (HWND list, const char *
271  BOOL CALLBACK  BOOL CALLBACK
272  file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
273  {  {
     const char *file;  
       
274      switch (msg) {      switch (msg) {
275      case WM_INITDIALOG:              case WM_INITDIALOG:
276          file = (const char*)lparam;          if (do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST),
277          assert (file != NULL);                               (const char*)lparam) < 1) {
         if (do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file) < 1) {  
278              msg_box (dlg, _("No valid OpenPGP data found."),              msg_box (dlg, _("No valid OpenPGP data found."),
279                       _("File Status"), MB_ERR);                       _("File Status"), MB_ERR);
280              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);

Legend:
Removed from v.327  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26