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

Annotation of /trunk/Src/wptSigList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (hide annotations)
Sat Nov 5 12:28:12 2005 UTC (19 years, 3 months ago) by twoaday
File size: 5371 byte(s)
More minor fixes...

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26