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

Diff of /trunk/Src/wptSigList.cpp

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

revision 69 by twoaday, Sat Nov 5 12:28:12 2005 UTC revision 204 by twoaday, Wed Apr 26 06:37:23 2006 UTC
# Line 1  Line 1 
1  /* wptSigList.cpp - Listview for key signatures  /* wptSigList.cpp - Listview for key signatures
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005, 2006 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
# Line 26  Line 26 
26  #include <windows.h>  #include <windows.h>
27  #include <time.h>  #include <time.h>
28    
29    #include "resource.h"
30  #include "wptGPG.h"  #include "wptGPG.h"
31  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
32  #include "wptKeylist.h"  #include "wptKeylist.h"
33  #include "wptNLS.h"  #include "wptNLS.h"
 #include "wptUTF8.h"  
34  #include "wptErrors.h"  #include "wptErrors.h"
35  #include "wptTypes.h"  #include "wptTypes.h"
36  #include "wptW32API.h"  #include "wptW32API.h"
37    #include "wptVersion.h"
38    
39    
40  /* Is the given signature an user-id signature? */  /* Is the given signature an user-id signature? */
# Line 50  siglist_build (listview_ctrl_t * lv, HWN Line 51  siglist_build (listview_ctrl_t * lv, HWN
51      struct listview_column_s implist[] = {      struct listview_column_s implist[] = {
52          {0, 240, (char *)_("User ID")},          {0, 240, (char *)_("User ID")},
53          {1,  50, (char *)_("Valid")},          {1,  50, (char *)_("Valid")},
54          {2,  40, (char *)_("Class")},          {2,  44, (char *)_("Class")},
55          {3,  68, (char *)_("Creation")},          {3,  68, (char *)_("Creation")},
56          {4,  80, (char *)_("Key ID")},          {4,  80, (char *)_("Key ID")},
57          {5,  68, (char *)_("Expiration")},          {5,  68, (char *)_("Expiration")},
58          {6,  56, (char *)_("Algorithm")},          {6,  56, (char *)_("Algorithm")},
59          {0,   0, NULL}          {0,   0, NULL}
60      };        };
61      int j, rc = 0;      int j, rc = 0;
62            
63      rc = listview_new (&c);      rc = listview_new (&c);
64      if (rc)      if (rc)
65          return rc;          return rc;
66      c->ctrl = ctrl;      c->ctrl = ctrl;
67      for ( j=0; implist[j].fieldname != NULL; j++ )      for  (j=0; implist[j].fieldname != NULL; j++)
68          listview_add_column( c, &implist[j] );          listview_add_column (c, &implist[j]);
69      listview_set_ext_style( c );      listview_set_ext_style (c);
70        listview_del_all_items (c);
71      *lv = c;      *lv = c;
72      return 0;      return 0;
73  }  }
# Line 75  siglist_build (listview_ctrl_t * lv, HWN Line 77  siglist_build (listview_ctrl_t * lv, HWN
77  void  void
78  siglist_delete( listview_ctrl_t lv )  siglist_delete( listview_ctrl_t lv )
79  {  {
80      if( lv ) {      if (lv) {
81          listview_release( lv );          listview_release (lv);
82      }      }
83  }  }
84    
# Line 99  indent_string (const char * old, int ilv Line 101  indent_string (const char * old, int ilv
101  }  }
102    
103    
104    /* Add an item at the given pos @pos with the opaque param @ks. */
105    int
106    add_keysig_item (listview_ctrl_t ctx, int pos, gpgme_key_sig_t ks)
107    {
108        LV_ITEM lvi;
109    
110        memset (&lvi, 0, sizeof lvi);
111        lvi.iItem = pos;
112        lvi.lParam = (LPARAM)ks;
113        lvi.mask = LVIF_PARAM;
114        if (ListView_InsertItem (ctx->ctrl, &lvi) != pos)
115            return -1;
116        return 0;
117    }
118    
119    
120  /* Add an userid signature @ks from the userid @uid to the sig list  /* Add an userid signature @ks from the userid @uid to the sig list
121     control @lv.     control @lv.
122     Return value: 0 on success. */     Return value: 0 on success. */
123  static int  static int
124  siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid, gpgme_key_sig_t ks)  siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid,
125                     gpgme_key_sig_t ks, int pos)
126  {  {
127      gpgme_key_t key=NULL;      gpgme_key_t key=NULL;
128      char t[128];      char t[128];
129      const char *attr;      const char *attr;
130      const char *s;      const char *s;
131      int rc = 0, key_attr;      int key_attr, no_uid = 0;
132        int rc = 0;
133    
134      if (ks && !IS_UID_CERT (ks->sig_class))      if (ks && !IS_UID_CERT (ks->sig_class))
135          return 0;          return 0;
136        
137      rc = listview_add_item (lv, " ");      rc = add_keysig_item (lv, pos, ks);
138      if( rc )          if (rc)
139          return rc;          return rc;
140    
141      attr = NULL;      attr = NULL;
# Line 127  siglist_add_key (listview_ctrl_t lv, gpg Line 147  siglist_add_key (listview_ctrl_t lv, gpg
147      else      else
148          attr = uid->uid;          attr = uid->uid;
149      if (attr && strlen (attr)) {      if (attr && strlen (attr)) {
150          char *uid_utf8 = utf8_to_wincp (attr, strlen (attr));          char *p = uid? m_strdup (attr) : indent_string (attr, 2);
151          char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2);          listview_add_sub_item (lv, pos, 0, p);
         listview_add_sub_item (lv, 0, 0, p);  
         free (uid_utf8);  
152          free_if_alloc (p);          free_if_alloc (p);
153      }      }
154      else      else {
155          listview_add_sub_item (lv, 0, 0, _("  user ID not found"));          listview_add_sub_item (lv, pos, 0, _("  user ID not found"));
156            no_uid = 1;
157        }
158    
159      if (uid)      if (uid)
160          return 0;          return 0;
# Line 145  siglist_add_key (listview_ctrl_t lv, gpg Line 165  siglist_add_key (listview_ctrl_t lv, gpg
165      case GPG_ERR_BAD_SIGNATURE:s = "NO";    break;      case GPG_ERR_BAD_SIGNATURE:s = "NO";    break;
166      default:                   s = "ERROR"; break;      default:                   s = "ERROR"; break;
167      }      }
168      listview_add_sub_item( lv, 0, 1, s );      if (no_uid)
169            s = "NOKEY";
170        listview_add_sub_item (lv, pos, 1, s);
171    
172      switch (ks->sig_class) {      switch (ks->sig_class) {
173      case 0x10: strcpy (t, " "); break;      case 0x10: strcpy (t, " "); break;
# Line 159  siglist_add_key (listview_ctrl_t lv, gpg Line 181  siglist_add_key (listview_ctrl_t lv, gpg
181          strcat (t, "L");          strcat (t, "L");
182      /*if (key_attr & GPGME_SIGF_NREV)      /*if (key_attr & GPGME_SIGF_NREV)
183          strcat (t, "R");*/          strcat (t, "R");*/
184      listview_add_sub_item (lv, 0, 2, t);      listview_add_sub_item (lv, pos, 2, t);
185    
186      key_attr = ks->timestamp;      key_attr = ks->timestamp;
187      if( key_attr ) {      if( key_attr ) {
188          s = get_key_created( key_attr );          s = get_key_created (key_attr);
189          listview_add_sub_item( lv, 0, 3, s );          listview_add_sub_item (lv, pos, 3, s);
190      }      }
191            
192      attr = ks->keyid;      attr = ks->keyid;
193      if( attr && strlen( attr ) == 16 ) {      if (attr && strlen (attr) == 16) {
194          _snprintf (t, sizeof t -1, "0x%s", attr + 8);          _snprintf (t, sizeof (t) -1, "0x%s", attr + 8);
195          listview_add_sub_item( lv, 0, 4, t );          listview_add_sub_item (lv, pos, 4, t);
196      }      }
197    
198      key_attr = ks->expires;      key_attr = ks->expires;
199      if (key_attr) {      if (key_attr) {
200          s = get_key_created (key_attr);          s = get_key_created (key_attr);
201          listview_add_sub_item (lv, 0, 5, s);          listview_add_sub_item (lv, pos, 5, s);
202      }      }
203    
204      attr = get_key_pubalgo (ks->pubkey_algo);      attr = get_key_pubalgo (ks->pubkey_algo);
205      if( attr )      if (attr)
206          listview_add_sub_item( lv, 0, 6, (char *)attr );          listview_add_sub_item (lv, pos, 6, (char *)attr);
207        
208      return 0;      return 0;
209  }  }
210    
# Line 197  siglist_load (HWND ctrl, const char *key Line 219  siglist_load (HWND ctrl, const char *key
219      gpgme_user_id_t u;      gpgme_user_id_t u;
220      gpgme_key_sig_t s;      gpgme_key_sig_t s;
221      listview_ctrl_t lv;      listview_ctrl_t lv;
222        int pos = 0;
223      int rc;      int rc;
224    
225      if (siglist_build (&lv, ctrl))      if (siglist_build (&lv, ctrl))
# Line 205  siglist_load (HWND ctrl, const char *key Line 228  siglist_load (HWND ctrl, const char *key
228      if (rc)      if (rc)
229          BUG (NULL);          BUG (NULL);
230    
     /* XXX: the root item is at the end but should come first. */  
231      for (u=key->uids; u; u = u->next) {      for (u=key->uids; u; u = u->next) {
232          siglist_add_key (lv, u, NULL);          siglist_add_key (lv, u, NULL, pos++);
233          for (s = u->signatures; s; s = s->next) {          for (s = u->signatures; s; s = s->next) {
234              rc = siglist_add_key (lv, NULL, s);              if (!IS_UID_CERT (s->sig_class))
235                    continue;
236                rc = siglist_add_key (lv, NULL, s, pos++);
237              if (rc)              if (rc)
238                  break;                  break;
239          }          }
# Line 220  siglist_load (HWND ctrl, const char *key Line 244  siglist_load (HWND ctrl, const char *key
244      }      }
245      return lv;      return lv;
246  }  }
247    
248    
249    /* Integer comparsion of @a and @b.
250       Return values: same as in strcmp. */
251    static inline int
252    int_cmp (int a, int b)
253    {
254        if (a == b) return 0;      
255        else if (a > b) return 1;
256        else return -1;
257        return 0;
258    }
259    
260    
261    /* Sorting callback for the signature list. */
262    static int CALLBACK
263    siglist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
264    {
265        gpgme_key_sig_t a, b;
266        int cmpresult=0;
267    
268        a = (gpgme_key_sig_t)first;
269        b = (gpgme_key_sig_t)second;
270        if (!a || !b)
271            return -1; /* this indicates that one item is a root item. */
272    
273        switch (sortby) {
274        case KEY_SORT_KEYID:
275            cmpresult = strcmp (a->keyid, b->keyid);
276            break;
277    
278        case KEY_SORT_CREATED:
279            cmpresult = int_cmp (a->timestamp, b->timestamp);
280            break;
281    
282        case KEY_SORT_ALGO:
283            cmpresult = int_cmp (a->pubkey_algo, b->pubkey_algo);
284            break;
285    
286        case KEY_SORT_VALIDITY:
287            cmpresult = int_cmp (a->status, b->status);
288            break;
289    
290        case SIG_SORT_EXPIRE:
291            cmpresult = int_cmp (a->expires, a->expires);
292            break;
293    
294        case SIG_SORT_CLASS:
295            cmpresult = int_cmp (a->sig_class, b->sig_class);
296            break;
297        }
298        return cmpresult;
299    }
300    
301    
302    /* Sort the signature list @sigl by @sortby. */
303    void
304    siglist_sort (listview_ctrl_t sigl, int sortby)
305    {
306        listview_sort_items (sigl, sortby, siglist_cmp_cb);
307    }

Legend:
Removed from v.69  
changed lines
  Added in v.204

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26