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

Legend:
Removed from v.24  
changed lines
  Added in v.69

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26