/[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 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
1  /* wptSigList.cpp - Listview for key signatures  /* wptSigList.cpp - Listview for key signatures
2   *      Copyright (C) 2001-2004 Timo Schulz   *      Copyright (C) 2001-2005 Timo Schulz
3   *   *      Copyright (C) 2005 g10 Code GmbH
4   * This file is part of WinPT.   *
5   *   * This file is part of WinPT.
6   * WinPT is free software; you can redistribute it and/or   *
7   * modify it under the terms of the GNU General Public License   * WinPT is free software; you can redistribute it and/or
8   * as published by the Free Software Foundation; either version 2   * modify it under the terms of the GNU General Public License
9   * of the License, or (at your option) any later version.   * as published by the Free Software Foundation; either version 2
10   *     * of the License, or (at your option) any later version.
11   * WinPT is distributed in the hope that it will be useful,   *  
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * WinPT is distributed in the hope that it will be useful,
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * General Public License for more details.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   *   * General Public License for more details.
16   * You should have received a copy of the GNU General Public License   *
17   * along with WinPT; if not, write to the Free Software Foundation,   * You should have received a copy of the GNU General Public License
18   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * along with WinPT; if not, write to the Free Software Foundation,
19   */   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21  #include <windows.h>  
22  #include <time.h>  #ifdef HAVE_CONFIG_H
23    #include <config.h>
24  #include "wptGPG.h"  #endif
25  #include "wptCommonCtl.h"  
26  #include "wptKeylist.h"  #include <windows.h>
27  #include "wptNLS.h"  #include <windows.h>
28  #include "wptUTF8.h"  #include <time.h>
29  #include "wptErrors.h"  
30  #include "wptTypes.h"  #include "wptGPG.h"
31  #include "wptW32API.h"  #include "wptCommonCtl.h"
32    #include "wptKeylist.h"
33    #include "wptNLS.h"
34  #define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13)  #include "wptUTF8.h"
35    #include "wptErrors.h"
36  static int  #include "wptTypes.h"
37  siglist_build( listview_ctrl_t * lv, HWND ctrl )  #include "wptW32API.h"
38  {  
39      struct listview_ctrl_s *c;  
40      struct listview_column_s implist[] = {  /* Is the given signature an user-id signature? */
41          {0, 240, (char *)_("User ID")},  #define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13)
42          {1,  50, (char *)_("Valid")},  
43          {2,  40, (char *)_("Class")},  
44          {3,  68, (char *)_("Creation")},  /* Create a signature list control in @lv with the parent window
45          {4,  80, (char *)_("Key ID")},     given in @ctrl.
46          {5,  68, (char *)_("Expiration")},     Return value: 0 on success. */
47          {6,  56, (char *)_("Algorithm")},  static int
48          {0,   0, NULL}  siglist_build (listview_ctrl_t * lv, HWND ctrl)
49      };    {
50      int j, rc = 0;      struct listview_ctrl_s *c;
51            struct listview_column_s implist[] = {
52      rc = listview_new( &c );          {0, 240, (char *)_("User ID")},
53      if( rc )          {1,  50, (char *)_("Valid")},
54          return rc;          {2,  40, (char *)_("Class")},
55      c->ctrl = ctrl;          {3,  68, (char *)_("Creation")},
56      for ( j=0; implist[j].fieldname != NULL; j++ )          {4,  80, (char *)_("Key ID")},
57          listview_add_column( c, &implist[j] );          {5,  68, (char *)_("Expiration")},
58      listview_set_ext_style( c );          {6,  56, (char *)_("Algorithm")},
59      *lv = c;          {0,   0, NULL}
60      return 0;      };  
61  } /* siglist_build */      int j, rc = 0;
62        
63        rc = listview_new (&c);
64  void      if (rc)
65  siglist_delete( listview_ctrl_t lv )          return rc;
66  {      c->ctrl = ctrl;
67      if( lv ) {      for ( j=0; implist[j].fieldname != NULL; j++ )
68          listview_release( lv );          listview_add_column( c, &implist[j] );
69      }      listview_set_ext_style( c );
70  } /* siglist_delete */      *lv = c;
71        return 0;
72    }
73  static char *  
74  indent_string( const char * old, int ilvl )  
75  {  /* Delete the signature control in @lv. */
76      char * p;  void
77      int i;  siglist_delete( listview_ctrl_t lv )
78    {
79      p = new char[strlen( old ) + 1 + ilvl];      if( lv ) {
80      if( !p )          listview_release( lv );
81          BUG( NULL );      }
82      for( i = 0; i < ilvl; i++ )  }
83          p[i] = ' ';  
84      strcpy( p+i, old );  
85      return p;  /* Indent the string in @old with the level @ilvl.
86  } /* indent_string */      Return value: indented string. */
87    static char *
88    indent_string (const char * old, int ilvl)
89  static int  {
90  siglist_add_key( listview_ctrl_t lv, gpgme_key_t key, int idx )      char * p;
91  {      int i;
92      char t[128];  
93      const char *attr;      p = new char[strlen (old) + 1 + ilvl];
94      const char *s;      if (!p)
95      int sig_class;          BUG (NULL);
96      int rc = 0, key_attr, root = 0;      for (i = 0; i < ilvl; i++)
97                p[i] = ' ';
98      s = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );      strcpy (p+i, old);
99      root = s && strlen( s )? 0 : 1;      return p;
100    }
101      sig_class = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_CLASS, NULL, idx );  
102      if( !IS_UID_CERT( sig_class ) && !root )  
103          return 0;  /* Add an userid signature @ks from the userid @uid to the sig list
104       control @lv.
105      rc = listview_add_item( lv, " " );     Return value: 0 on success. */
106      if( rc )      static int
107          return rc;  siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid, gpgme_key_sig_t ks)
108    {
109      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_ISSUER, NULL, idx );      gpgme_key_t key=NULL;
110      if( attr && strlen( attr ) ) {      char t[128];
111          char * uid = utf8_to_wincp (attr, strlen (attr)), * p;      const char *attr;
112          p = root? m_strdup( uid ) : indent_string( uid, 2 );      const char *s;
113          listview_add_sub_item( lv, 0, 0, p );      int rc = 0, key_attr;
114          free( uid );  
115          free_if_alloc( p );      if (ks && !IS_UID_CERT (ks->sig_class))
116      }          return 0;
117      else  
118          listview_add_sub_item( lv, 0, 0, _("  user ID not found") );      rc = listview_add_item (lv, " ");
119        if( rc )    
120      if( root )          return rc;
121          return 0;  
122        attr = NULL;
123      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_STAT, NULL, idx );      if (!uid) {
124      if( key_attr == GPGME_SIG_STAT_NONE )                get_pubkey (ks->keyid, &key);
125          return WPTERR_GENERAL;          if (key)
126      switch (key_attr) {              attr = key->uids->uid;
127      case GPGME_SIG_STAT_GOOD: s = "YES";   break;      }
128      case GPGME_SIG_STAT_NOKEY:s = "NOKEY"; break;      else
129      case GPGME_SIG_STAT_BAD:  s = "NO";    break;          attr = uid->uid;
130      case GPGME_SIG_STAT_NOSIG:s = "NOSIG"; break;      if (attr && strlen (attr)) {
131      case GPGME_SIG_STAT_ERROR:          char *uid_utf8 = utf8_to_wincp (attr, strlen (attr));
132      default:                  s = "ERROR"; break;          char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2);
133      }          listview_add_sub_item (lv, 0, 0, p);
134      listview_add_sub_item( lv, 0, 1, s );          free (uid_utf8);
135            free_if_alloc (p);
136      switch (sig_class) {      }
137      case 0x10: strcpy (t, " "); break;      else
138      case 0x11: strcpy (t, "1"); break;          listview_add_sub_item (lv, 0, 0, _("  user ID not found"));
139      case 0x12: strcpy (t, "2"); break;  
140      case 0x13: strcpy (t, "3"); break;      if (uid)
141      }          return 0;
142      key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_FLAGS, NULL, idx);  
143      if (key_attr)      switch (gpgme_err_code (ks->status)) {
144          strcat (t, " ");      case GPG_ERR_NO_ERROR:     s = "YES";   break;
145      if (key_attr & GPGME_SIGF_LOCAL)      case GPG_ERR_NO_PUBKEY:    s = "NOKEY"; break;
146          strcat (t, "L");      case GPG_ERR_BAD_SIGNATURE:s = "NO";    break;
147      if (key_attr & GPGME_SIGF_NREV)      default:                   s = "ERROR"; break;
148          strcat (t, "R");      }
149      listview_add_sub_item (lv, 0, 2, t);      listview_add_sub_item( lv, 0, 1, s );
150    
151      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_CREATED, NULL, idx );      switch (ks->sig_class) {
152      if( key_attr ) {      case 0x10: strcpy (t, " "); break;
153          s = get_key_created( key_attr );      case 0x11: strcpy (t, "1"); break;
154          listview_add_sub_item( lv, 0, 3, s );      case 0x12: strcpy (t, "2"); break;
155      }      case 0x13: strcpy (t, "3"); break;
156            }
157      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );          
158      if( attr && strlen( attr ) == 16 ) {      strcat (t, " ");
159          _snprintf( t, sizeof t -1, "0x%s", attr + 8 );      if (!ks->exportable)
160          listview_add_sub_item( lv, 0, 4, t );          strcat (t, "L");
161      }      /*if (key_attr & GPGME_SIGF_NREV)
162            strcat (t, "R");*/
163      key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_EXPIRES, NULL, idx);      listview_add_sub_item (lv, 0, 2, t);
164      if (key_attr)  
165      {      key_attr = ks->timestamp;
166          s = get_key_created (key_attr);      if( key_attr ) {
167          listview_add_sub_item (lv, 0, 5, s);          s = get_key_created( key_attr );
168      }          listview_add_sub_item( lv, 0, 3, s );
169        }
170      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_ALGO, NULL, idx );      
171      attr = gpgme_key_expand_attr( GPGME_ATTR_ALGO, key_attr );      attr = ks->keyid;
172      if( attr )      if( attr && strlen( attr ) == 16 ) {
173          listview_add_sub_item( lv, 0, 6, (char *)attr );          _snprintf (t, sizeof t -1, "0x%s", attr + 8);
174                listview_add_sub_item( lv, 0, 4, t );
175      return 0;      }
176  } /* siglist_add_key */  
177        key_attr = ks->expires;
178        if (key_attr) {
179  listview_ctrl_t          s = get_key_created (key_attr);
180  siglist_load( HWND ctrl, const char *keyid )          listview_add_sub_item (lv, 0, 5, s);
181  {          }
182      gpgme_key_t key;  
183      listview_ctrl_t lv;      attr = get_key_pubalgo (ks->pubkey_algo);
184      int rc = 0, i;      if( attr )
185            listview_add_sub_item( lv, 0, 6, (char *)attr );
186      if( siglist_build( &lv, ctrl ) )      
187          BUG( NULL );      return 0;
188      rc = get_pubkey( keyid, &key );  }
189      if( rc )  
190          BUG( NULL );  
191      for( i = 0; i < gpgme_key_count_items( key, GPGME_ATTR_SIG_KEYID ); i++ ) {  /* Load a signature list with the signatures of the key with
192          rc = siglist_add_key( lv, key, i );     the keyID @keyid. The parent window is in @ctrl.
193          if( rc )     Return value is the handle to the listview control. */
194              break;  listview_ctrl_t
195      }  siglist_load (HWND ctrl, const char *keyid)
196      if( rc ) {  {    
197          siglist_delete( lv );      gpgme_key_t key;
198          lv = NULL;      gpgme_user_id_t u;
199      }      gpgme_key_sig_t s;
200      return lv;      listview_ctrl_t lv;
201  } /* siglist_load */      int rc, i=0;
202    
203        if (siglist_build (&lv, ctrl))
204            BUG (NULL);
205        rc = get_pubkey(keyid, &key);
206        if (rc)
207            BUG (NULL);
208    
209        /* XXX: the root item is at the end but should come first. */
210        for (u=key->uids; u; u = u->next) {
211            siglist_add_key (lv, u, NULL);
212            for (s = u->signatures; s; s = s->next) {
213                rc = siglist_add_key (lv, NULL, s);
214                if (rc)
215                    break;
216            }
217        }
218        if (rc) {
219            siglist_delete (lv);
220            lv = NULL;
221        }
222        return lv;
223    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26