/[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 48 by werner, Mon Oct 31 21:14:11 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 <time.h>
28  #include "wptUTF8.h"  
29  #include "wptErrors.h"  #include "wptGPG.h"
30  #include "wptTypes.h"  #include "wptCommonCtl.h"
31  #include "wptW32API.h"  #include "wptKeylist.h"
32    #include "wptNLS.h"
33    #include "wptUTF8.h"
34  #define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13)  #include "wptErrors.h"
35    #include "wptTypes.h"
36  static int  #include "wptW32API.h"
37  siglist_build( listview_ctrl_t * lv, HWND ctrl )  
38  {  
39      struct listview_ctrl_s *c;  /* Is the given signature an user-id signature? */
40      struct listview_column_s implist[] = {  #define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13)
41          {0, 240, (char *)_("User ID")},  
42          {1,  50, (char *)_("Valid")},  
43          {2,  40, (char *)_("Class")},  /* Create a signature list control in @lv with the parent window
44          {3,  68, (char *)_("Creation")},     given in @ctrl.
45          {4,  80, (char *)_("Key ID")},     Return value: 0 on success. */
46          {5,  68, (char *)_("Expiration")},  static int
47          {6,  56, (char *)_("Algorithm")},  siglist_build (listview_ctrl_t * lv, HWND ctrl)
48          {0,   0, NULL}  {
49      };        struct listview_ctrl_s *c;
50      int j, rc = 0;      struct listview_column_s implist[] = {
51                {0, 240, (char *)_("User ID")},
52      rc = listview_new( &c );          {1,  50, (char *)_("Valid")},
53      if( rc )          {2,  40, (char *)_("Class")},
54          return rc;          {3,  68, (char *)_("Creation")},
55      c->ctrl = ctrl;          {4,  80, (char *)_("Key ID")},
56      for ( j=0; implist[j].fieldname != NULL; j++ )          {5,  68, (char *)_("Expiration")},
57          listview_add_column( c, &implist[j] );          {6,  56, (char *)_("Algorithm")},
58      listview_set_ext_style( c );          {0,   0, NULL}
59      *lv = c;      };  
60      return 0;      int j, rc = 0;
61  } /* siglist_build */      
62        rc = listview_new (&c);
63        if (rc)
64  void          return rc;
65  siglist_delete( listview_ctrl_t lv )      c->ctrl = ctrl;
66  {      for ( j=0; implist[j].fieldname != NULL; j++ )
67      if( lv ) {          listview_add_column( c, &implist[j] );
68          listview_release( lv );      listview_set_ext_style( c );
69      }      *lv = c;
70  } /* siglist_delete */      return 0;
71    }
72    
73  static char *  
74  indent_string( const char * old, int ilvl )  /* Delete the signature control in @lv. */
75  {  void
76      char * p;  siglist_delete( listview_ctrl_t lv )
77      int i;  {
78        if( lv ) {
79      p = new char[strlen( old ) + 1 + ilvl];          listview_release( lv );
80      if( !p )      }
81          BUG( NULL );  }
82      for( i = 0; i < ilvl; i++ )  
83          p[i] = ' ';  
84      strcpy( p+i, old );  /* Indent the string in @old with the level @ilvl.
85      return p;      Return value: indented string. */
86  } /* indent_string */  static char *
87    indent_string (const char * old, int ilvl)
88    {
89  static int      char * p;
90  siglist_add_key( listview_ctrl_t lv, gpgme_key_t key, int idx )      int i;
91  {  
92      char t[128];      p = new char[strlen (old) + 1 + ilvl];
93      const char *attr;      if (!p)
94      const char *s;          BUG (NULL);
95      int sig_class;      for (i = 0; i < ilvl; i++)
96      int rc = 0, key_attr, root = 0;          p[i] = ' ';
97            strcpy (p+i, old);
98      s = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );      return p;
99      root = s && strlen( s )? 0 : 1;  }
100    
101      sig_class = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_CLASS, NULL, idx );  
102      if( !IS_UID_CERT( sig_class ) && !root )  /* Add an userid signature @ks from the userid @uid to the sig list
103          return 0;     control @lv.
104       Return value: 0 on success. */
105      rc = listview_add_item( lv, " " );  static int
106      if( rc )      siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid, gpgme_key_sig_t ks)
107          return rc;  {
108        gpgme_key_t key=NULL;
109      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_ISSUER, NULL, idx );      char t[128];
110      if( attr && strlen( attr ) ) {      const char *attr;
111          char * uid = utf8_to_wincp (attr, strlen (attr)), * p;      const char *s;
112          p = root? m_strdup( uid ) : indent_string( uid, 2 );      int rc = 0, key_attr;
113          listview_add_sub_item( lv, 0, 0, p );  
114          free( uid );      if (ks && !IS_UID_CERT (ks->sig_class))
115          free_if_alloc( p );          return 0;
116      }  
117      else      rc = listview_add_item (lv, " ");
118          listview_add_sub_item( lv, 0, 0, _("  user ID not found") );      if( rc )    
119            return rc;
120      if( root )  
121          return 0;      attr = NULL;
122        if (!uid) {
123      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_STAT, NULL, idx );          get_pubkey (ks->keyid, &key);
124      if( key_attr == GPGME_SIG_STAT_NONE )                if (key)
125          return WPTERR_GENERAL;              attr = key->uids->uid;
126      switch (key_attr) {      }
127      case GPGME_SIG_STAT_GOOD: s = "YES";   break;      else
128      case GPGME_SIG_STAT_NOKEY:s = "NOKEY"; break;          attr = uid->uid;
129      case GPGME_SIG_STAT_BAD:  s = "NO";    break;      if (attr && strlen (attr)) {
130      case GPGME_SIG_STAT_NOSIG:s = "NOSIG"; break;          char *uid_utf8 = utf8_to_wincp (attr, strlen (attr));
131      case GPGME_SIG_STAT_ERROR:          char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2);
132      default:                  s = "ERROR"; break;          listview_add_sub_item (lv, 0, 0, p);
133      }          free (uid_utf8);
134      listview_add_sub_item( lv, 0, 1, s );          free_if_alloc (p);
135        }
136      switch (sig_class) {      else
137      case 0x10: strcpy (t, " "); break;          listview_add_sub_item (lv, 0, 0, _("  user ID not found"));
138      case 0x11: strcpy (t, "1"); break;  
139      case 0x12: strcpy (t, "2"); break;      if (uid)
140      case 0x13: strcpy (t, "3"); break;          return 0;
141      }  
142      key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_FLAGS, NULL, idx);      switch (gpgme_err_code (ks->status)) {
143      if (key_attr)      case GPG_ERR_NO_ERROR:     s = "YES";   break;
144          strcat (t, " ");      case GPG_ERR_NO_PUBKEY:    s = "NOKEY"; break;
145      if (key_attr & GPGME_SIGF_LOCAL)      case GPG_ERR_BAD_SIGNATURE:s = "NO";    break;
146          strcat (t, "L");      default:                   s = "ERROR"; break;
147      if (key_attr & GPGME_SIGF_NREV)      }
148          strcat (t, "R");      listview_add_sub_item( lv, 0, 1, s );
149      listview_add_sub_item (lv, 0, 2, t);  
150        switch (ks->sig_class) {
151      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_CREATED, NULL, idx );      case 0x10: strcpy (t, " "); break;
152      if( key_attr ) {      case 0x11: strcpy (t, "1"); break;
153          s = get_key_created( key_attr );      case 0x12: strcpy (t, "2"); break;
154          listview_add_sub_item( lv, 0, 3, s );      case 0x13: strcpy (t, "3"); break;
155      }      }
156                
157      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );      strcat (t, " ");
158      if( attr && strlen( attr ) == 16 ) {      if (!ks->exportable)
159          _snprintf( t, sizeof t -1, "0x%s", attr + 8 );          strcat (t, "L");
160          listview_add_sub_item( lv, 0, 4, t );      /*if (key_attr & GPGME_SIGF_NREV)
161      }          strcat (t, "R");*/
162        listview_add_sub_item (lv, 0, 2, t);
163      key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_EXPIRES, NULL, idx);  
164      if (key_attr)      key_attr = ks->timestamp;
165      {      if( key_attr ) {
166          s = get_key_created (key_attr);          s = get_key_created( key_attr );
167          listview_add_sub_item (lv, 0, 5, s);          listview_add_sub_item( lv, 0, 3, s );
168      }      }
169        
170      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_ALGO, NULL, idx );      attr = ks->keyid;
171      attr = gpgme_key_expand_attr( GPGME_ATTR_ALGO, key_attr );      if( attr && strlen( attr ) == 16 ) {
172      if( attr )          _snprintf (t, sizeof t -1, "0x%s", attr + 8);
173          listview_add_sub_item( lv, 0, 6, (char *)attr );          listview_add_sub_item( lv, 0, 4, t );
174            }
175      return 0;  
176  } /* siglist_add_key */      key_attr = ks->expires;
177        if (key_attr) {
178            s = get_key_created (key_attr);
179  listview_ctrl_t          listview_add_sub_item (lv, 0, 5, s);
180  siglist_load( HWND ctrl, const char *keyid )      }
181  {      
182      gpgme_key_t key;      attr = get_key_pubalgo (ks->pubkey_algo);
183      listview_ctrl_t lv;      if( attr )
184      int rc = 0, i;          listview_add_sub_item( lv, 0, 6, (char *)attr );
185        
186      if( siglist_build( &lv, ctrl ) )      return 0;
187          BUG( NULL );  }
188      rc = get_pubkey( keyid, &key );  
189      if( rc )  
190          BUG( NULL );  /* Load a signature list with the signatures of the key with
191      for( i = 0; i < gpgme_key_count_items( key, GPGME_ATTR_SIG_KEYID ); i++ ) {     the keyID @keyid. The parent window is in @ctrl.
192          rc = siglist_add_key( lv, key, i );     Return value is the handle to the listview control. */
193          if( rc )  listview_ctrl_t
194              break;  siglist_load (HWND ctrl, const char *keyid)
195      }  {    
196      if( rc ) {      gpgme_key_t key;
197          siglist_delete( lv );      gpgme_user_id_t u;
198          lv = NULL;      gpgme_key_sig_t s;
199      }      listview_ctrl_t lv;
200      return lv;      int rc, i=0;
201  } /* siglist_load */  
202        if (siglist_build (&lv, ctrl))
203            BUG (NULL);
204        rc = get_pubkey(keyid, &key);
205        if (rc)
206            BUG (NULL);
207    
208        /* XXX: the root item is at the end but should come first. */
209        for (u=key->uids; u; u = u->next) {
210            siglist_add_key (lv, u, NULL);
211            for (s = u->signatures; s; s = s->next) {
212                rc = siglist_add_key (lv, NULL, s);
213                if (rc)
214                    break;
215            }
216        }
217        if (rc) {
218            siglist_delete (lv);
219            lv = NULL;
220        }
221        return lv;
222    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26