LCOV - code coverage report
Current view: top level - tests - run-import.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 49 0.0 %
Date: 2016-09-12 12:35:26 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* pgp-import.c  - Helper to run an import command
       2             :    Copyright (C) 2008, 2009 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             : 
       6             :    GPGME is free software; you can redistribute it and/or modify it
       7             :    under the terms of the GNU Lesser General Public License as
       8             :    published by the Free Software Foundation; either version 2.1 of
       9             :    the License, or (at your option) any later version.
      10             : 
      11             :    GPGME is distributed in the hope that it will be useful, but
      12             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :    Lesser General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU Lesser General Public
      17             :    License along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : /* We need to include config.h so that we know whether we are building
      21             :    with large file system (LFS) support. */
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <stdlib.h>
      27             : #include <stdio.h>
      28             : #include <string.h>
      29             : 
      30             : #include <gpgme.h>
      31             : 
      32             : #define PGM "run-import"
      33             : 
      34             : #include "run-support.h"
      35             : 
      36             : 
      37             : static int verbose;
      38             : 
      39             : 
      40             : static int
      41           0 : show_usage (int ex)
      42             : {
      43           0 :   fputs ("usage: " PGM " [options] FILENAMEs\n\n"
      44             :          "Options:\n"
      45             :          "  --verbose        run in verbose mode\n"
      46             :          "  --url            import from given URLs\n"
      47             :          "  -0               URLs are delimited by a nul\n"
      48             :          , stderr);
      49           0 :   exit (ex);
      50             : }
      51             : 
      52             : int
      53           0 : main (int argc, char **argv)
      54             : {
      55           0 :   int last_argc = -1;
      56             :   gpgme_error_t err;
      57             :   gpgme_ctx_t ctx;
      58           0 :   int url_mode = 0;
      59           0 :   int nul_mode = 0;
      60             :   gpgme_import_result_t impres;
      61             :   gpgme_data_t data;
      62             : 
      63           0 :   if (argc)
      64           0 :     { argc--; argv++; }
      65           0 :   while (argc && last_argc != argc )
      66             :     {
      67           0 :       last_argc = argc;
      68           0 :       if (!strcmp (*argv, "--"))
      69             :         {
      70           0 :           argc--; argv++;
      71           0 :           break;
      72             :         }
      73           0 :       else if (!strcmp (*argv, "--help"))
      74           0 :         show_usage (0);
      75           0 :       else if (!strcmp (*argv, "--verbose"))
      76             :         {
      77           0 :           verbose = 1;
      78           0 :           argc--; argv++;
      79             :         }
      80           0 :       else if (!strcmp (*argv, "--url"))
      81             :         {
      82           0 :           url_mode = 1;
      83           0 :           argc--; argv++;
      84             :         }
      85           0 :       else if (!strcmp (*argv, "-0"))
      86             :         {
      87           0 :           nul_mode = 1;
      88           0 :           argc--; argv++;
      89             :         }
      90           0 :       else if (!strncmp (*argv, "--", 2))
      91           0 :         show_usage (1);
      92             : 
      93             :     }
      94             : 
      95           0 :   if (!argc)
      96           0 :     show_usage (1);
      97             : 
      98           0 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
      99             : 
     100           0 :   err = gpgme_new (&ctx);
     101           0 :   fail_if_err (err);
     102           0 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_OpenPGP);
     103             : 
     104           0 :   for (; argc; argc--, argv++)
     105             :     {
     106           0 :       printf ("reading file `%s'\n", *argv);
     107           0 :       err = gpgme_data_new_from_file (&data, *argv, 1);
     108           0 :       fail_if_err (err);
     109             : 
     110           0 :       if (url_mode)
     111           0 :         gpgme_data_set_encoding (data, (nul_mode? GPGME_DATA_ENCODING_URL0
     112             :                                         : GPGME_DATA_ENCODING_URL));
     113             : 
     114           0 :       err = gpgme_op_import (ctx, data);
     115           0 :       fail_if_err (err);
     116           0 :       impres = gpgme_op_import_result (ctx);
     117           0 :       if (!impres)
     118             :         {
     119           0 :           fprintf (stderr, PGM ": no import result returned\n");
     120           0 :           exit (1);
     121             :         }
     122           0 :       print_import_result (impres);
     123             : 
     124           0 :       gpgme_data_release (data);
     125             :     }
     126             : 
     127           0 :   gpgme_release (ctx);
     128           0 :   return 0;
     129             : }

Generated by: LCOV version 1.11