gpg: Change parse_packet to take a context.
[gnupg.git] / g10 / mainproc.c
index 0c979f8..30d9b18 100644 (file)
 #include <time.h>
 
 #include "gpg.h"
-#include "util.h"
+#include "../common/util.h"
 #include "packet.h"
-#include "iobuf.h"
+#include "../common/iobuf.h"
 #include "options.h"
 #include "keydb.h"
 #include "filter.h"
 #include "main.h"
-#include "status.h"
-#include "i18n.h"
+#include "../common/status.h"
+#include "../common/i18n.h"
 #include "trustdb.h"
 #include "keyserver-internal.h"
 #include "photoid.h"
-#include "mbox-util.h"
+#include "../common/mbox-util.h"
 #include "call-dirmngr.h"
 
 /* Put an upper limit on nested packets.  The 32 is an arbitrary
@@ -78,7 +78,7 @@ struct mainproc_context
      signature. */
   struct
   {
-    /* A file descriptor of the the signed data.  Only used if not -1. */
+    /* A file descriptor of the signed data.  Only used if not -1. */
     int data_fd;
     /* A list of filenames with the data files or NULL. This is only
        used if DATA_FD is -1. */
@@ -1015,8 +1015,13 @@ list_node (CTX c, kbnode_t node)
 
           keyid_from_pk( pk, keyid );
           if (pk->flags.primary)
-            c->trustletter = (opt.fast_list_mode?
-                              0 : get_validity_info (c->ctrl, pk, NULL));
+            c->trustletter = (opt.fast_list_mode
+                              ? 0
+                              : get_validity_info
+                                  (c->ctrl,
+                                   node->pkt->pkttype == PKT_PUBLIC_KEY
+                                   ? node : NULL,
+                                   pk, NULL));
           es_printf ("%s:", pk->flags.primary? "pub":"sub" );
           if (c->trustletter)
             es_putc (c->trustletter, es_stdout);
@@ -1027,7 +1032,7 @@ list_node (CTX c, kbnode_t node)
                      colon_datestr_from_pk( pk ),
                      colon_strtime (pk->expiredate) );
           if (pk->flags.primary && !opt.fast_list_mode)
-            es_putc (get_ownertrust_info (pk), es_stdout);
+            es_putc (get_ownertrust_info (pk, 1), es_stdout);
           es_putc (':', es_stdout);
           es_putc ('\n', es_stdout);
         }
@@ -1325,6 +1330,7 @@ static int
 do_proc_packets (ctrl_t ctrl, CTX c, iobuf_t a)
 {
   PACKET *pkt;
+  struct parse_packet_ctx_s parsectx;
   int rc = 0;
   int any_data = 0;
   int newpkt;
@@ -1336,7 +1342,8 @@ do_proc_packets (ctrl_t ctrl, CTX c, iobuf_t a)
   pkt = xmalloc( sizeof *pkt );
   c->iobuf = a;
   init_packet(pkt);
-  while ((rc=parse_packet(a, pkt)) != -1)
+  init_parse_packet (&parsectx, a);
+  while ((rc=parse_packet (&parsectx, pkt)) != -1)
     {
       any_data = 1;
       if (rc)
@@ -1955,11 +1962,11 @@ check_sig_and_print (CTX c, kbnode_t node)
             continue;
           if (!un->pkt->pkt.user_id->created)
             continue;
-          if (un->pkt->pkt.user_id->is_revoked)
+          if (un->pkt->pkt.user_id->flags.revoked)
             continue;
-          if (un->pkt->pkt.user_id->is_expired)
+          if (un->pkt->pkt.user_id->flags.expired)
             continue;
-          if (!un->pkt->pkt.user_id->is_primary)
+          if (!un->pkt->pkt.user_id->flags.primary)
             continue;
           /* We want the textual primary user ID here */
           if (un->pkt->pkt.user_id->attrib_data)
@@ -1973,8 +1980,8 @@ check_sig_and_print (CTX c, kbnode_t node)
             does not print a LF we need to compute the validity
             before calling that function.  */
           if ((opt.verify_options & VERIFY_SHOW_UID_VALIDITY))
-            valid = get_validity (c->ctrl, mainpk, un->pkt->pkt.user_id,
-                                  NULL, 0);
+            valid = get_validity (c->ctrl, keyblock, mainpk,
+                                  un->pkt->pkt.user_id, NULL, 0);
           else
             valid = 0; /* Not used.  */
 
@@ -1992,7 +1999,7 @@ check_sig_and_print (CTX c, kbnode_t node)
 
       log_assert (mainpk);
 
-      /* In case we did not found a valid valid textual userid above
+      /* In case we did not found a valid textual userid above
          we print the first user id packet or a "[?]" instead along
          with the "Good|Expired|Bad signature" line.  */
       if (!count)
@@ -2036,12 +2043,12 @@ check_sig_and_print (CTX c, kbnode_t node)
             {
               if (un->pkt->pkttype != PKT_USER_ID)
                 continue;
-              if ((un->pkt->pkt.user_id->is_revoked
-                   || un->pkt->pkt.user_id->is_expired)
+              if ((un->pkt->pkt.user_id->flags.revoked
+                   || un->pkt->pkt.user_id->flags.expired)
                   && !(opt.verify_options & VERIFY_SHOW_UNUSABLE_UIDS))
                 continue;
               /* Skip textual primary user ids which we printed above. */
-              if (un->pkt->pkt.user_id->is_primary
+              if (un->pkt->pkt.user_id->flags.primary
                   && !un->pkt->pkt.user_id->attrib_data )
                 continue;
 
@@ -2066,16 +2073,16 @@ check_sig_and_print (CTX c, kbnode_t node)
                 {
                   const char *valid;
 
-                  if (un->pkt->pkt.user_id->is_revoked)
+                  if (un->pkt->pkt.user_id->flags.revoked)
                     valid = _("revoked");
-                  else if (un->pkt->pkt.user_id->is_expired)
+                  else if (un->pkt->pkt.user_id->flags.expired)
                     valid = _("expired");
                   else
                    /* Since this is just informational, don't
                       actually ask the user to update any trust
                       information.  */
                     valid = (trust_value_to_string
-                             (get_validity (c->ctrl, mainpk,
+                             (get_validity (c->ctrl, keyblock, mainpk,
                                             un->pkt->pkt.user_id, NULL, 0)));
                   log_printf (" [%s]\n",valid);
                 }
@@ -2203,6 +2210,8 @@ check_sig_and_print (CTX c, kbnode_t node)
             }
         }
 
+      free_public_key (pk);
+      pk = NULL;
       release_kbnode( keyblock );
       if (rc)
         g10_errors_seen = 1;
@@ -2216,7 +2225,7 @@ check_sig_and_print (CTX c, kbnode_t node)
       snprintf (buf, sizeof buf, "%08lX%08lX %d %d %02x %lu %d",
                 (ulong)sig->keyid[0], (ulong)sig->keyid[1],
                 sig->pubkey_algo, sig->digest_algo,
-                sig->sig_class, (ulong)sig->timestamp, rc);
+                sig->sig_class, (ulong)sig->timestamp, gpg_err_code (rc));
       write_status_text (STATUS_ERRSIG, buf);
       if (gpg_err_code (rc) == GPG_ERR_NO_PUBKEY)
         {