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

Annotation of /trunk/Src/wptKeyTrustPathDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 304 - (hide annotations)
Wed Mar 21 10:59:31 2007 UTC (17 years, 11 months ago) by twoaday
File size: 5149 byte(s)


1 werner 36 /* wptKeyTrustPathDlg.cpp - List a trust path for a key.
2     * Copyright (C) 2001, 2002, 2003 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (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
14     * GNU 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     #if 0
21     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptGPGME.h"
30     #include "wptCommonCtl.h"
31     #include "wptContext.h" /* for passphrase_s */
32     #include "wptDlgs.h"
33     #include "wptTypes.h"
34     #include "wptNLS.h"
35    
36     struct trust_path_s {
37     int level;
38     int type;
39     char otrust[2];
40     char valid[2];
41     char keyid[16+1];
42     char uid[128];
43     };
44    
45    
46     static void
47     copy_trust_item(trust_path_s *tp, GpgmeTrustItem ti)
48     {
49     const char *t;
50    
51     tp->level = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_LEVEL, NULL, 0 );
52     tp->type = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_TYPE, NULL, 0 );
53     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_OTRUST, NULL, 0);
54     strcpy( tp->otrust, t );
55     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_VALIDITY, NULL, 0 );
56     strcpy( tp->valid, t );
57     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_KEYID, NULL, 0 );
58     strcpy( tp->keyid, t );
59     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_USERID, NULL, 0 );
60     strcpy( tp->uid, t );
61     } /* copy_trust_item */
62    
63    
64     static HTREEITEM
65     treeview_insert_item( HWND tree, HTREEITEM parent, const char *text )
66     {
67     TVINSERTSTRUCT ti;
68     HTREEITEM node;
69    
70     memset( &ti, 0, sizeof ti );
71     ti.hParent = parent;
72     ti.hInsertAfter = TVI_LAST;
73     ti.item.mask = TVIF_TEXT;
74     ti.item.pszText = (char *)text;
75     node = TreeView_InsertItem( tree, &ti );
76     return node;
77     } /* treeview_insert_item */
78    
79    
80     HTREEITEM
81     treeview_create_child_item( HWND tree, trust_path_s *tp, HTREEITEM parent )
82     {
83     char info[1024];
84     HTREEITEM node;
85    
86     if( tp->type == 0 ) /* root */
87 twoaday 304 _snprintf (info, DIM (info)-1, "%s", tp->uid );
88 werner 36 else if( tp->type == 1 )/* key */
89 twoaday 304 _snprintf (info, DIM (info) -1, "0x%s (otrust=%s, validity=%s)",
90 werner 36 tp->keyid, tp->otrust, tp->valid );
91     else if( tp->type == 2 ) /* userid */
92 twoaday 304 _snprintf (info, DI M(info) -1, "%s (validity=%s)",
93     tp->uid, tp->valid );
94 werner 36 node = treeview_insert_item( tree, parent, info );
95     return node;
96     } /* treeview_create_child_item */
97    
98    
99     void
100     treeview_add_trustpath(HWND tree, HTREEITEM node, trust_path_s c[], int n, int level)
101     {
102     HTREEITEM _node;
103     int i;
104    
105     for( i=0; i<n; i++ ) {
106     if( c[i].level == level ) {
107     _node = treeview_create_child_item( tree, &c[i], node );
108     treeview_add_trustpath( tree, _node, c, n, i );
109     }
110     }
111     } /* treeview_add_trustpath */
112    
113    
114     BOOL CALLBACK
115     keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
116     {
117     winpt_key_t k;
118     HWND tree;
119     GpgmeTrustItem trust_item;
120     gpgme_ctx_t ctx;
121     gpgme_error_t ec;
122     trust_path_s tp[256] = {0};
123     int pos = 0;
124    
125     switch( msg ) {
126     case WM_INITDIALOG:
127     if( !lparam )
128     dlg_fatal_error( dlg, "Could not get dialog param!" );
129     k = (winpt_key_t )lparam;
130     SetWindowText( dlg, _("List Trust Path") );
131     tree = GetDlgItem( dlg, IDC_KEYTRUST_TREE );
132     ec = gpgme_new( &ctx );
133     if( ec )
134     BUG( NULL );
135     ec = gpgme_op_trustlist_start( ctx, k->keyid, 6 );
136     if( ec ) {
137     msg_box( dlg, gpgme_strerror( err ), _("Trustlist"), MB_ERR );
138     gpgme_release( ctx );
139     return FALSE;
140     }
141     memset( &tp[0], 0, sizeof tp[0] );
142     tp[0].level = -1; pos++;
143     strcpy( tp[0].uid, k->uid );
144     strcpy( tp[0].keyid, k->keyid );
145    
146     while( !gpgme_op_trustlist_next( ctx, &trust_item ) ) {
147     copy_trust_item( &tp[pos++], trust_item );
148     if( pos > 256 )
149     break;
150     gpgme_trust_item_release( trust_item );
151     }
152     gpgme_release( ctx );
153     treeview_add_trustpath( tree, NULL, tp, pos, -1 );
154     return TRUE;
155    
156     case WM_SYSCOMMAND:
157     if( LOWORD( wparam ) == SC_CLOSE )
158     EndDialog( dlg, FALSE );
159     return FALSE;
160    
161     case WM_COMMAND:
162     switch( LOWORD(wparam) ) {
163     case IDOK:
164     EndDialog( dlg, TRUE );
165     return TRUE;
166     }
167     }
168    
169     return FALSE;
170 twoaday 2 } /* keytrust_dlg_proc */
171 werner 36 #else
172     #include <windows.h>
173     BOOL CALLBACK keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam,
174     LPARAM lparam ) { return FALSE; }
175     /* GPG 1.2.x does not support this yet */
176     #endif

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26