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

Annotation of /trunk/Src/wptSigList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 5552 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptSigList.cpp - Listview for key signatures
2     * Copyright (C) 2001-2004 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     * General Public License for more details.
15     *
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,
18     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include <windows.h>
22     #include <time.h>
23    
24     #include "wptGPG.h"
25     #include "wptCommonCtl.h"
26     #include "wptKeylist.h"
27     #include "wptNLS.h"
28     #include "wptUTF8.h"
29     #include "wptErrors.h"
30     #include "wptTypes.h"
31     #include "wptW32API.h"
32    
33    
34     #define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13)
35    
36     static int
37     siglist_build( listview_ctrl_t * lv, HWND ctrl )
38     {
39     struct listview_ctrl_s *c;
40     struct listview_column_s implist[] = {
41     {0, 240, (char *)_("User ID")},
42     {1, 50, (char *)_("Valid")},
43     {2, 40, (char *)_("Class")},
44     {3, 68, (char *)_("Creation")},
45     {4, 80, (char *)_("Key ID")},
46     {5, 68, (char *)_("Expiration")},
47     {6, 56, (char *)_("Algorithm")},
48     {0, 0, NULL}
49     };
50     int j, rc = 0;
51    
52     rc = listview_new( &c );
53     if( rc )
54     return rc;
55     c->ctrl = ctrl;
56     for ( j=0; implist[j].fieldname != NULL; j++ )
57     listview_add_column( c, &implist[j] );
58     listview_set_ext_style( c );
59     *lv = c;
60     return 0;
61     } /* siglist_build */
62    
63    
64     void
65     siglist_delete( listview_ctrl_t lv )
66     {
67     if( lv ) {
68     listview_release( lv );
69     }
70     } /* siglist_delete */
71    
72    
73     static char *
74     indent_string( const char * old, int ilvl )
75     {
76     char * p;
77     int i;
78    
79     p = new char[strlen( old ) + 1 + ilvl];
80     if( !p )
81     BUG( NULL );
82     for( i = 0; i < ilvl; i++ )
83     p[i] = ' ';
84     strcpy( p+i, old );
85     return p;
86     } /* indent_string */
87    
88    
89     static int
90     siglist_add_key( listview_ctrl_t lv, gpgme_key_t key, int idx )
91     {
92     char t[128];
93     const char *attr;
94     const char *s;
95     int sig_class;
96     int rc = 0, key_attr, root = 0;
97    
98     s = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );
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 )
103     return 0;
104    
105     rc = listview_add_item( lv, " " );
106     if( rc )
107     return rc;
108    
109     attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_ISSUER, NULL, idx );
110     if( attr && strlen( attr ) ) {
111     char * uid = utf8_to_wincp (attr, strlen (attr)), * p;
112     p = root? m_strdup( uid ) : indent_string( uid, 2 );
113     listview_add_sub_item( lv, 0, 0, p );
114     free( uid );
115     free_if_alloc( p );
116     }
117     else
118     listview_add_sub_item( lv, 0, 0, _(" user ID not found") );
119    
120     if( root )
121     return 0;
122    
123     key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_STAT, NULL, idx );
124     if( key_attr == GPGME_SIG_STAT_NONE )
125     return WPTERR_GENERAL;
126     switch (key_attr) {
127     case GPGME_SIG_STAT_GOOD: s = "YES"; break;
128     case GPGME_SIG_STAT_NOKEY:s = "NOKEY"; break;
129     case GPGME_SIG_STAT_BAD: s = "NO"; break;
130     case GPGME_SIG_STAT_NOSIG:s = "NOSIG"; break;
131     case GPGME_SIG_STAT_ERROR:
132     default: s = "ERROR"; break;
133     }
134     listview_add_sub_item( lv, 0, 1, s );
135    
136     switch (sig_class) {
137     case 0x10: strcpy (t, " "); break;
138     case 0x11: strcpy (t, "1"); break;
139     case 0x12: strcpy (t, "2"); break;
140     case 0x13: strcpy (t, "3"); break;
141     }
142     key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_FLAGS, NULL, idx);
143     if (key_attr)
144     strcat (t, " ");
145     if (key_attr & GPGME_SIGF_LOCAL)
146     strcat (t, "L");
147     if (key_attr & GPGME_SIGF_NREV)
148     strcat (t, "R");
149     listview_add_sub_item (lv, 0, 2, t);
150    
151     key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_SIG_CREATED, NULL, idx );
152     if( key_attr ) {
153     s = get_key_created( key_attr );
154     listview_add_sub_item( lv, 0, 3, s );
155     }
156    
157     attr = gpgme_key_get_string_attr( key, GPGME_ATTR_SIG_KEYID, NULL, idx );
158     if( attr && strlen( attr ) == 16 ) {
159     _snprintf( t, sizeof t -1, "0x%s", attr + 8 );
160     listview_add_sub_item( lv, 0, 4, t );
161     }
162    
163     key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_SIG_EXPIRES, NULL, idx);
164     if (key_attr)
165     {
166     s = get_key_created (key_attr);
167     listview_add_sub_item (lv, 0, 5, s);
168     }
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 );
172     if( attr )
173     listview_add_sub_item( lv, 0, 6, (char *)attr );
174    
175     return 0;
176     } /* siglist_add_key */
177    
178    
179     listview_ctrl_t
180     siglist_load( HWND ctrl, const char *keyid )
181     {
182     gpgme_key_t key;
183     listview_ctrl_t lv;
184     int rc = 0, i;
185    
186     if( siglist_build( &lv, ctrl ) )
187     BUG( NULL );
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++ ) {
192     rc = siglist_add_key( lv, key, i );
193     if( rc )
194     break;
195     }
196     if( rc ) {
197     siglist_delete( lv );
198     lv = NULL;
199     }
200     return lv;
201     } /* siglist_load */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26