gpg: Use a common filter_getval for import and export.
authorWerner Koch <wk@gnupg.org>
Mon, 5 Sep 2016 06:31:25 +0000 (08:31 +0200)
committerWerner Koch <wk@gnupg.org>
Mon, 5 Sep 2016 07:52:04 +0000 (09:52 +0200)
* g10/import.c (filter_getval): Rename to ...
(impex_filter_getval): this.  Make global.
(apply_keep_uid_filter, apply_drop_sig_filter): Adjust.
* g10/export.c (filter_getval): Remove.
(apply_drop_sig_filter): Use impex_filter_getval.

Signed-off-by: Werner Koch <wk@gnupg.org>
g10/export.c
g10/import.c
g10/main.h

index 8c15868..e0699db 100644 (file)
@@ -1293,37 +1293,6 @@ write_keyblock_to_output (kbnode_t keyblock, int with_armor,
 }
 
 
-/* Helper for apply_keep_uid_filter.  */
-static const char *
-filter_getval (void *cookie, const char *propname)
-{
-  kbnode_t node = cookie;
-  const char *result;
-
-  if (node->pkt->pkttype == PKT_USER_ID)
-    {
-      if (!strcmp (propname, "uid"))
-        result = node->pkt->pkt.user_id->name;
-      else if (!strcmp (propname, "mbox"))
-        {
-          if (!node->pkt->pkt.user_id->mbox)
-            {
-              node->pkt->pkt.user_id->mbox
-                = mailbox_from_userid (node->pkt->pkt.user_id->name);
-            }
-          return node->pkt->pkt.user_id->mbox;
-        }
-      else if (!strcmp (propname, "primary"))
-        result = node->pkt->pkt.user_id->is_primary? "1":"0";
-      else
-        result = NULL;
-    }
-  else
-    result = NULL;
-
-  return result;
-}
-
 /*
  * Apply the keep-uid filter to the keyblock.  The deleted nodes are
  * marked and thus the caller should call commit_kbnode afterwards.
@@ -1338,7 +1307,7 @@ apply_keep_uid_filter (kbnode_t keyblock, recsel_expr_t selector)
     {
       if (node->pkt->pkttype == PKT_USER_ID)
         {
-          if (!recsel_select (selector, filter_getval, node))
+          if (!recsel_select (selector, impex_filter_getval, node))
             {
               /* log_debug ("keep-uid: deleting '%s'\n", */
               /*            node->pkt->pkt.user_id->name); */
index f7cb923..14abd2b 100644 (file)
@@ -1103,9 +1103,9 @@ check_prefs (ctrl_t ctrl, kbnode_t keyblock)
 }
 
 
-/* Helper for apply_keep_uid_filter and apply_drop_sig_filter.  */
-static const char *
-filter_getval (void *cookie, const char *propname)
+/* Helper for apply_*_filter in im,port.c and export.c.  */
+const char *
+impex_filter_getval (void *cookie, const char *propname)
 {
   /* FIXME: Malloc our static buffers and access them via the cookie.  */
   kbnode_t node = cookie;
@@ -1178,7 +1178,7 @@ apply_keep_uid_filter (kbnode_t keyblock, recsel_expr_t selector)
     {
       if (node->pkt->pkttype == PKT_USER_ID)
         {
-          if (!recsel_select (selector, filter_getval, node))
+          if (!recsel_select (selector, impex_filter_getval, node))
             {
 
               /* log_debug ("keep-uid: deleting '%s'\n", */
@@ -1237,7 +1237,7 @@ apply_drop_sig_filter (kbnode_t keyblock, recsel_expr_t selector)
 
       if (IS_UID_SIG(sig) || IS_UID_REV(sig))
         {
-          if (recsel_select (selector, filter_getval, node))
+          if (recsel_select (selector, impex_filter_getval, node))
             delete_kbnode (node);
         }
     }
index 340f3b3..b1563d2 100644 (file)
@@ -368,6 +368,7 @@ gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
 import_stats_t import_new_stats_handle (void);
 void import_release_stats_handle (import_stats_t hd);
 void import_print_stats (import_stats_t hd);
+const char *impex_filter_getval (void *cookie, const char *propname);
 gpg_error_t transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats,
                                   kbnode_t sec_keyblock, int batch, int force);