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

Diff of /trunk/Src/wptVerifyList.cpp

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

revision 19 by twoaday, Fri May 20 08:39:15 2005 UTC revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC
# Line 17  Line 17 
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   */   */
 /* x-todo-status: OK */  
   
20  #include <windows.h>  #include <windows.h>
21  #include <time.h>  #include <time.h>
22    
# Line 32  Line 30 
30  #include "wptW32API.h"  #include "wptW32API.h"
31    
32    
33  static char *  /* Extract the file name part out of the given path in @path.
34  extract_filename( const char * path )     Return value: file part or NULL on error. */
35    static char*
36    extract_filename (const char *path)
37  {  {
38      char * fname, * p;      char * fname, *p;
39      int n, len = 0;      int n, len = 0;
40    
41      p = strrchr( path, '\\' );      p = strrchr (path, '\\');
42      if( !p )      if (!p)
43          return m_strdup( path );          return m_strdup (path);
44      n = p - path;      n = p - path;
45      len = strlen( path ) - n;      len = strlen (path) - n;
46      fname = new char[len+1];      fname = new char[len+1];
47      if( !fname )      if (!fname)
48          BUG( NULL );              BUG (NULL);
49      memcpy( fname, path+n+1, len );      memcpy (fname, path+n+1, len);
50      fname[len] = '\0';      fname[len] = '\0';
51      return fname;      return fname;
52  } /* extract_filename */  }
53    
54    
55    /* String representaton of the time in @timestamp.
56       Format YEAR-MON-DAY HOUR:MIN:SEC.
57       Return value: time as formatted string. */
58  const char *  const char *
59  strtimestamp( long timestamp )  strtimestamp (long timestamp)
60  {  {
61      static char timebuf[64] = {0};      static char timebuf[64] = {0};
62      struct tm * warp;      struct tm * warp;
63            
64      warp = localtime( &timestamp );      warp = localtime (&timestamp);
65      _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",      _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",
66                 warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,                       warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,      
67                 warp->tm_hour, warp->tm_min, warp->tm_sec );                 warp->tm_hour, warp->tm_min, warp->tm_sec);
68      return timebuf;      return timebuf;
69  } /* strtimestamp */  }
70    
71    
72    /* Map the signature summary in @sum to signature status table index.
73       Return value: index to table. */
74  int  int
75  verlist_build (listview_ctrl_t * lv, HWND ctrl, int fm_mode)  sigsum_to_index (gpgme_sigsum_t sum)
76    {
77        if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED))
78            return 7;
79        if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED))
80            return 6;
81        if (sum & GPGME_SIGSUM_GREEN)
82            return 1;
83        else if (sum & GPGME_SIGSUM_RED)
84            return 2;
85        else if (sum & GPGME_SIGSUM_KEY_MISSING)
86            return 3;
87        return 0;
88    }
89    
90    
91    /* Build a verify signature list control. With the parent window
92       from @ctrl and the mod given in @fm_mode. @lv contains the
93       new control on success.
94       Return value: 0 on success. */
95    int
96    verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode)
97  {  {
98      int j, rc = 0;      int j, rc = 0;
99      struct listview_ctrl_s * c;      struct listview_ctrl_s * c;
# Line 105  verlist_build (listview_ctrl_t * lv, HWN Line 131  verlist_build (listview_ctrl_t * lv, HWN
131      listview_set_ext_style( c );      listview_set_ext_style( c );
132      *lv = c;      *lv = c;
133      return 0;      return 0;
134  } /* verlist_build */  }
135    
136    
137    /* Delete the given verify control in @lv. */
138  void  void
139  verlist_delete( listview_ctrl_t lv )  verlist_delete (listview_ctrl_t lv)
140  {  {
141      if( lv ) {      if (lv) {
142          listview_release( lv );          listview_release (lv);  
143      }      }
144  } /* verlist_delete */  }
145    
146    
147    /* Add the given signature in @sig to the verify control @lv.
148       Return value: 0 on success. */
149  int  int
150  verlist_add_sig( listview_ctrl_t lv, gpgme_sig_t sig )  verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)
151  {  {
152      gpgme_key_t key;      gpgme_key_t key = NULL;
153      const char * attr;      const char * attr;
154      u32 key_attr, t;      u32 key_attr, t;
155      char keyid[32+1];      char keyid[32+1];
# Line 129  verlist_add_sig( listview_ctrl_t lv, gpg Line 158  verlist_add_sig( listview_ctrl_t lv, gpg
158      if( listview_add_item( lv, " " ) )      if( listview_add_item( lv, " " ) )
159          return WPTERR_GENERAL;          return WPTERR_GENERAL;
160            
161      if( !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE ) )      get_pubkey (sig->fpr, &key);
         return WPTERR_GENERAL; /* No key was stored */  
162            
163      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY );      attr = get_gpg_sigstat (sig->summary);
     attr = gpg_sigstat[t % SIGSTAT_MASK];  
164      if( attr )      if( attr )
165          listview_add_sub_item( lv, 0, 0, (char *)attr );          listview_add_sub_item( lv, 0, 0, (char *)attr );
166            
167      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED );      t = sig->timestamp;
168      attr = strtimestamp( t );      attr = strtimestamp (t);
169      if( attr )      if( attr )
170          listview_add_sub_item( lv, 0, 1, (char *)attr );          listview_add_sub_item (lv, 0, 1, (char *)attr);
171            
172      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE );      attr = _("Unknown");
173      key = (gpgme_key_t)t;      if (key) {
174      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 );          key_attr = key->uids->validity;
175      attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, key_attr );          attr = get_key_trust2 (NULL, key_attr, 0, 0);
176      if( attr )      }
177          listview_add_sub_item( lv, 0, 2, (char *)attr );      listview_add_sub_item( lv, 0, 2, (char *)attr );
178            
179      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 );      attr = sig->fpr;
180      if ( !attr || strlen( attr ) < 8 )      if (!attr || strlen (attr) < 8)
181          attr = "DEADBEEFDEADBEEF";          listview_add_sub_item (lv, 0, 3, "0xDEADBEEF");
182      _snprintf( keyid, sizeof keyid -1, "0x%s", attr + 8 );      else {
183      listview_add_sub_item( lv, 0, 3, keyid );          if (strlen (attr) == 40)
184                attr += 32;
185            else
186                attr += 24;
187            _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
188            listview_add_sub_item (lv, 0, 3, keyid);
189        }
190            
191      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, 0 );      if (!key) {
     if( !attr ) {  
192          attr = _("Invalid User ID");          attr = _("Invalid User ID");
193          listview_add_sub_item( lv, 0, 4, (char *)attr );          listview_add_sub_item( lv, 0, 4, (char *)attr );
194      }        }
195      else {      else {
196            attr = key->uids->name;
197          uid = utf8_to_wincp (attr, strlen (attr));          uid = utf8_to_wincp (attr, strlen (attr));
198          if ( uid ) {          if (uid) {
199              listview_add_sub_item( lv, 0, 4, (char *)uid );              listview_add_sub_item( lv, 0, 4, (char *)uid );
200              free( uid );              free( uid );
201          }          }
202      }      }
203        
204      return 0;      return 0;
205  } /* verlist_add_sig */  }
206    
207    
208    /* Add the given file signature in @log to the verify control @lv.
209       Return value: 0 on success. */
210  int  int
211  verlist_add_sig_log( listview_ctrl_t lv, siglog_context_t log )  verlist_add_sig_log (listview_ctrl_t lv, siglog_context_t log)
212  {  {
213      gpgme_sig_t sig = log->sig;      gpgme_signature_t sig = log->sig;
214      const char * attr;          gpgme_key_t key = NULL;
215      char t[64], * name;      const char *attr;    
216      u32 i_attr;      char t[64], *name;
217    
218      if( listview_add_item( lv, "" ) )      if( listview_add_item( lv, "" ) )
219          return WPTERR_GENERAL;          return WPTERR_GENERAL;
220    
221        get_pubkey (sig->fpr, &key);
222            
223      name = extract_filename( log->file );      name = extract_filename (log->file);
224      if( name )      if( name )
225          listview_add_sub_item( lv, 0, 0, name );          listview_add_sub_item (lv, 0, 0, name);
226      free_if_alloc( name );      free_if_alloc (name);
227            
228      i_attr = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY );      attr = get_gpg_sigstat (sig->summary);
     attr = gpg_sigstat[i_attr % SIGSTAT_MASK];  
229      if( attr )      if( attr )
230          listview_add_sub_item( lv, 0, 1, attr );          listview_add_sub_item( lv, 0, 1, attr );
231    
232      attr = strtimestamp( gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ) );      attr = strtimestamp( sig->timestamp );
233      if( attr )      if( attr )
234          listview_add_sub_item( lv, 0, 2, attr );          listview_add_sub_item( lv, 0, 2, attr );
235            
236      attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY,      attr = _("Unknown");
237                                    gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_OTRUST ) );      if (key)
238      if( attr )          attr = get_key_trust2 (NULL, key->owner_trust, 0, 0);
239          listview_add_sub_item( lv, 0, 3, attr );      listview_add_sub_item( lv, 0, 3, attr );
240            
241      attr = gpgme_sig_get_string_attr( sig, GPGME_ATTR_KEYID );      attr = sig->fpr;
242      if( !log->use_uid && strlen( attr ) == 16 ) {      if( !log->use_uid && strlen( attr ) == 40 ) {
243          _snprintf( t, sizeof t-1, "0x%s", attr + 8 );          _snprintf( t, sizeof t-1, "0x%s", attr + 32 );
244          listview_add_sub_item( lv, 0, 4, t );          listview_add_sub_item( lv, 0, 4, t );
245      }      }
246      else if( !log->use_uid && strlen( attr ) == 8 ) {      else if( !log->use_uid && strlen( attr ) == 32 ) {
247          _snprintf( t, sizeof t-1, "0x%s", attr );          _snprintf( t, sizeof t-1, "0x%s", attr + 24 );
248          listview_add_sub_item( lv, 0, 4, t );          listview_add_sub_item( lv, 0, 4, t );
249      }      }
250      else if( log->user_id ) {      else if( log->user_id ) {
# Line 219  verlist_add_sig_log( listview_ctrl_t lv, Line 255  verlist_add_sig_log( listview_ctrl_t lv,
255          }          }
256      }      }
257      return 0;      return 0;
258  } /* verlist_add_sig_log */  }
259    

Legend:
Removed from v.19  
changed lines
  Added in v.23

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26