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

Annotation of /trunk/Src/wptKeyTrustPathDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 5192 byte(s)
First set of changes to use autotools for building.
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 <windows.h>
27     #include <commctrl.h>
28    
29     #include "../resource.h"
30     #include "wptGPGME.h"
31     #include "wptCommonCtl.h"
32     #include "wptContext.h" /* for passphrase_s */
33     #include "wptDlgs.h"
34     #include "wptTypes.h"
35     #include "wptNLS.h"
36    
37     struct trust_path_s {
38     int level;
39     int type;
40     char otrust[2];
41     char valid[2];
42     char keyid[16+1];
43     char uid[128];
44     };
45    
46    
47     static void
48     copy_trust_item(trust_path_s *tp, GpgmeTrustItem ti)
49     {
50     const char *t;
51    
52     tp->level = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_LEVEL, NULL, 0 );
53     tp->type = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_TYPE, NULL, 0 );
54     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_OTRUST, NULL, 0);
55     strcpy( tp->otrust, t );
56     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_VALIDITY, NULL, 0 );
57     strcpy( tp->valid, t );
58     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_KEYID, NULL, 0 );
59     strcpy( tp->keyid, t );
60     t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_USERID, NULL, 0 );
61     strcpy( tp->uid, t );
62     } /* copy_trust_item */
63    
64    
65     static HTREEITEM
66     treeview_insert_item( HWND tree, HTREEITEM parent, const char *text )
67     {
68     TVINSERTSTRUCT ti;
69     HTREEITEM node;
70    
71     memset( &ti, 0, sizeof ti );
72     ti.hParent = parent;
73     ti.hInsertAfter = TVI_LAST;
74     ti.item.mask = TVIF_TEXT;
75     ti.item.pszText = (char *)text;
76     node = TreeView_InsertItem( tree, &ti );
77     return node;
78     } /* treeview_insert_item */
79    
80    
81     HTREEITEM
82     treeview_create_child_item( HWND tree, trust_path_s *tp, HTREEITEM parent )
83     {
84     char info[1024];
85     HTREEITEM node;
86    
87     if( tp->type == 0 ) /* root */
88     _snprintf( info, sizeof info-1, "%s", tp->uid );
89     else if( tp->type == 1 )/* key */
90     _snprintf(info, sizeof info -1, "0x%s (otrust=%s, validity=%s)",
91     tp->keyid, tp->otrust, tp->valid );
92     else if( tp->type == 2 ) /* userid */
93     _snprintf( info, sizeof info -1, "%s (validity=%s)", tp->uid, tp->valid );
94     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     #ifndef LANG_DE
131     SetWindowText( dlg, _("List Trust Path") );
132     #endif
133     tree = GetDlgItem( dlg, IDC_KEYTRUST_TREE );
134     ec = gpgme_new( &ctx );
135     if( ec )
136     BUG( NULL );
137     ec = gpgme_op_trustlist_start( ctx, k->keyid, 6 );
138     if( ec ) {
139     msg_box( dlg, gpgme_strerror( err ), _("Trustlist"), MB_ERR );
140     gpgme_release( ctx );
141     return FALSE;
142     }
143     memset( &tp[0], 0, sizeof tp[0] );
144     tp[0].level = -1; pos++;
145     strcpy( tp[0].uid, k->uid );
146     strcpy( tp[0].keyid, k->keyid );
147    
148     while( !gpgme_op_trustlist_next( ctx, &trust_item ) ) {
149     copy_trust_item( &tp[pos++], trust_item );
150     if( pos > 256 )
151     break;
152     gpgme_trust_item_release( trust_item );
153     }
154     gpgme_release( ctx );
155     treeview_add_trustpath( tree, NULL, tp, pos, -1 );
156     return TRUE;
157    
158     case WM_SYSCOMMAND:
159     if( LOWORD( wparam ) == SC_CLOSE )
160     EndDialog( dlg, FALSE );
161     return FALSE;
162    
163     case WM_COMMAND:
164     switch( LOWORD(wparam) ) {
165     case IDOK:
166     EndDialog( dlg, TRUE );
167     return TRUE;
168     }
169     }
170    
171     return FALSE;
172 twoaday 2 } /* keytrust_dlg_proc */
173 werner 36 #else
174     #include <windows.h>
175     BOOL CALLBACK keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam,
176     LPARAM lparam ) { return FALSE; }
177     /* GPG 1.2.x does not support this yet */
178     #endif

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26