/[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 139 by twoaday, Wed Jan 11 12:19:41 2006 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 13  Line 13 
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.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
16   */   */
17    
18  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 26  Line 22 
22  #include <windows.h>  #include <windows.h>
23  #include <time.h>  #include <time.h>
24    
25    #include "resource.h"
26  #include "wptGPG.h"  #include "wptGPG.h"
27  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
28  #include "wptKeylist.h"  #include "wptKeylist.h"
29  #include "wptNLS.h"  #include "wptNLS.h"
 #include "wptUTF8.h"  
30  #include "wptErrors.h"  #include "wptErrors.h"
31  #include "wptTypes.h"  #include "wptTypes.h"
32  #include "wptW32API.h"  #include "wptW32API.h"
33    #include "wptVersion.h"
34    #include "wptContext.h"
35    
36    
37  /* Is the given signature an user-id signature? */  /* Is the given signature an user-id signature? */
# Line 43  Line 41 
41  /* Create a signature list control in @lv with the parent window  /* Create a signature list control in @lv with the parent window
42     given in @ctrl.     given in @ctrl.
43     Return value: 0 on success. */     Return value: 0 on success. */
44  static int  static void
45  siglist_build (listview_ctrl_t * lv, HWND ctrl)  siglist_build (listview_ctrl_t *lv, HWND ctrl)
46  {  {    
     struct listview_ctrl_s *c;  
47      struct listview_column_s implist[] = {      struct listview_column_s implist[] = {
48          {0, 240, (char *)_("User ID")},          {0, 240, (char *)_("User ID")},
49          {1,  50, (char *)_("Valid")},          {1,  50, (char *)_("Valid")},
# Line 56  siglist_build (listview_ctrl_t * lv, HWN Line 53  siglist_build (listview_ctrl_t * lv, HWN
53          {5,  68, (char *)_("Expiration")},          {5,  68, (char *)_("Expiration")},
54          {6,  56, (char *)_("Algorithm")},          {6,  56, (char *)_("Algorithm")},
55          {0,   0, NULL}          {0,   0, NULL}
56      };        };
57      int j, rc = 0;      listview_ctrl_t c;
58        
59      rc = listview_new (&c);      listview_new (&c, ctrl);
60      if (rc)      for  (int j=0; implist[j].fieldname != NULL; j++)
         return rc;  
     c->ctrl = ctrl;  
     for  (j=0; implist[j].fieldname != NULL; j++)  
61          listview_add_column (c, &implist[j]);          listview_add_column (c, &implist[j]);
62      listview_set_ext_style (c);      listview_set_ext_style (c);
63        listview_del_all_items (c);
64      *lv = c;      *lv = c;
     return 0;  
65  }  }
66    
67    
68  /* Delete the signature control in @lv. */  /* Delete the signature control in @lv. */
69  void  void
70  siglist_delete( listview_ctrl_t lv )  siglist_delete (listview_ctrl_t lv)
71  {  {
72      if (lv) {      if (lv) {
73          listview_release (lv);          listview_release (lv);
# Line 83  siglist_delete( listview_ctrl_t lv ) Line 77  siglist_delete( listview_ctrl_t lv )
77    
78  /* Indent the string in @old with the level @ilvl.  /* Indent the string in @old with the level @ilvl.
79      Return value: indented string. */      Return value: indented string. */
80  static char *  static char*
81  indent_string (const char * old, int ilvl)  indent_string (const char *old, int ilvl)
82  {  {
83      char * p;      char *p;
84      int i;      int i;
85        
86      p = new char[strlen (old) + 1 + ilvl];      p = new char[strlen (old) + 1 + ilvl];
87      if (!p)      if (!p)
88          BUG (NULL);          BUG (NULL);
# Line 100  indent_string (const char * old, int ilv Line 94  indent_string (const char * old, int ilv
94    
95    
96  /* Add an item at the given pos @pos with the opaque param @ks. */  /* Add an item at the given pos @pos with the opaque param @ks. */
97  int  static int
98  add_keysig_item (listview_ctrl_t ctx, int pos, gpgme_key_sig_t ks)  add_keysig_item (listview_ctrl_t ctx, int pos, gpgme_key_sig_t ks)
99  {  {
100      LV_ITEM lvi;      LV_ITEM lvi;
101    
102      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof (lvi));
103      lvi.iItem = pos;      lvi.iItem = pos;
104      lvi.lParam = (LPARAM)ks;      lvi.lParam = (LPARAM)ks;
105      lvi.mask = LVIF_PARAM;      lvi.mask = LVIF_PARAM;
# Line 119  add_keysig_item (listview_ctrl_t ctx, in Line 113  add_keysig_item (listview_ctrl_t ctx, in
113     control @lv.     control @lv.
114     Return value: 0 on success. */     Return value: 0 on success. */
115  static int  static int
116  siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid,  siglist_add_key (listview_ctrl_t lv, struct native_uid_s *uid,
117                   gpgme_key_sig_t ks, int pos)                   gpgme_key_sig_t ks, int pos)
118  {  {
119      gpgme_key_t key=NULL;      struct winpt_key_s key;    
     char t[128];  
120      const char *attr;      const char *attr;
121      const char *s;      const char *s;
122      int key_attr, no_uid = 0;      char t[128];
123      int rc = 0;      int no_uid = 0;
124        int rc;
125    
126      if (ks && !IS_UID_CERT (ks->sig_class))      if (ks && !IS_UID_CERT (ks->sig_class))
127          return 0;          return 0;
# Line 138  siglist_add_key (listview_ctrl_t lv, gpg Line 132  siglist_add_key (listview_ctrl_t lv, gpg
132    
133      attr = NULL;      attr = NULL;
134      if (!uid) {      if (!uid) {
135          get_pubkey (ks->keyid, &key);          memset (&key, 0, sizeof (key));
136          if (key)          winpt_get_pubkey (ks->keyid, &key);
137              attr = key->uids->uid;          if (key.ext != NULL)
138                attr = key.ext->uids->uid;
139      }      }
140      else      else
141          attr = uid->uid;          attr = uid->uid;
142      if (attr && strlen (attr)) {      if (attr && strlen (attr) > 0) {
143          char *uid_utf8 = utf8_to_wincp (attr, strlen (attr));          char *p = uid? m_strdup (attr) : indent_string (attr, 2);
144          char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2);          listview_add_sub_item (lv, pos, SL_COL_UID, p);
         listview_add_sub_item (lv, pos, 0, p);  
         free (uid_utf8);  
145          free_if_alloc (p);          free_if_alloc (p);
146      }      }
147      else {      else {
148          listview_add_sub_item (lv, pos, 0, _("  user ID not found"));          listview_add_sub_item (lv, pos, SL_COL_UID, _("  user ID not found"));
149          no_uid = 1;          no_uid = 1;
150      }      }
151    
152        /* Return immediately for root items. */
153      if (uid)      if (uid)
154          return 0;          return 0;
155    
156        /* TRANSLATORS: these strings should be in capital letters. */
157      switch (gpgme_err_code (ks->status)) {      switch (gpgme_err_code (ks->status)) {
158      case GPG_ERR_NO_ERROR:     s = "YES";   break;      case GPG_ERR_NO_ERROR:     s = _("YES");   break;
159      case GPG_ERR_NO_PUBKEY:    s = "NOKEY"; break;      case GPG_ERR_NO_PUBKEY:    s = _("NOKEY"); break;
160      case GPG_ERR_BAD_SIGNATURE:s = "NO";    break;      case GPG_ERR_BAD_SIGNATURE:s = _("NO");    break;
161      default:                   s = "ERROR"; break;      default:                   s = _("ERROR"); break;
162      }      }
163      if (no_uid)      if (ks->revoked)
164          s = "NOKEY";          s = _("REVOKED");
165      listview_add_sub_item (lv, pos, 1, s);      else if (no_uid)
166            s = _("NOKEY");
167        listview_add_sub_item (lv, pos, SL_COL_VALID, s);
168    
169      switch (ks->sig_class) {      switch (ks->sig_class) {
170      case 0x10: strcpy (t, " "); break;      case 0x10: strcpy (t, " "); break;
# Line 175  siglist_add_key (listview_ctrl_t lv, gpg Line 172  siglist_add_key (listview_ctrl_t lv, gpg
172      case 0x12: strcpy (t, "2"); break;      case 0x12: strcpy (t, "2"); break;
173      case 0x13: strcpy (t, "3"); break;      case 0x13: strcpy (t, "3"); break;
174      }      }
175            
176      strcat (t, " ");      strcat (t, " ");
177      if (!ks->exportable)      if (!ks->exportable)
178          strcat (t, "L");          strcat (t, "L");
179      /*if (key_attr & GPGME_SIGF_NREV)      listview_add_sub_item (lv, pos, SL_COL_CLASS, t);
180          strcat (t, "R");*/  
181      listview_add_sub_item (lv, pos, 2, t);      s = get_key_created (ks->timestamp);
182        listview_add_sub_item (lv, pos, SL_COL_CREATE, s);
183      key_attr = ks->timestamp;  
184      if( key_attr ) {      if (ks->keyid && strlen (ks->keyid) == 16) {
185          s = get_key_created (key_attr);          _snprintf (t, DIM (t) -1, "0x%s", ks->keyid + 8);
186          listview_add_sub_item (lv, pos, 3, s);          listview_add_sub_item (lv, pos, SL_COL_KEYID, t);
     }  
       
     attr = ks->keyid;  
     if (attr && strlen (attr) == 16) {  
         _snprintf (t, sizeof (t) -1, "0x%s", attr + 8);  
         listview_add_sub_item (lv, pos, 4, t);  
187      }      }
188    
189      key_attr = ks->expires;      if (ks->expires > 0) {
190      if (key_attr) {          s = get_key_created (ks->expires);
191          s = get_key_created (key_attr);          listview_add_sub_item (lv, pos, SL_COL_EXPIRE, s);
         listview_add_sub_item (lv, pos, 5, s);  
192      }      }
193    
194      attr = get_key_pubalgo (ks->pubkey_algo);      attr = get_key_pubalgo (ks->pubkey_algo);
# Line 215  siglist_add_key (listview_ctrl_t lv, gpg Line 205  siglist_add_key (listview_ctrl_t lv, gpg
205  listview_ctrl_t  listview_ctrl_t
206  siglist_load (HWND ctrl, const char *keyid)  siglist_load (HWND ctrl, const char *keyid)
207  {      {    
     gpgme_key_t key;  
     gpgme_user_id_t u;  
208      gpgme_key_sig_t s;      gpgme_key_sig_t s;
209        struct native_uid_s *u;
210        winpt_key_s key;
211      listview_ctrl_t lv;      listview_ctrl_t lv;
212      int pos = 0;      int pos = 0;
213      int rc;      int rc = 0;
214    
215      if (siglist_build (&lv, ctrl))      siglist_build (&lv, ctrl);
216          BUG (NULL);      memset (&key, 0, sizeof (key));
217      rc = get_pubkey(keyid, &key);      if (winpt_get_pubkey (keyid, &key))
     if (rc)  
218          BUG (NULL);          BUG (NULL);
219    
220      for (u=key->uids; u; u = u->next) {      for (u=key.ext->uids; u; u = u->next) {
221          siglist_add_key (lv, u, NULL, pos++);          siglist_add_key (lv, u, NULL, pos++);
222          for (s = u->signatures; s; s = s->next) {          for (s = u->signatures; s; s = s->next) {
223              if (!IS_UID_CERT (s->sig_class))              if (!IS_UID_CERT (s->sig_class))

Legend:
Removed from v.139  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26