1
/* pgp-import.c - Helper to run an import command
2
Copyright (C) 2008, 2009 g10 Code GmbH
4
This file is part of GPGME.
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.
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.
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/>.
20
/* We need to include config.h so that we know whether we are building
21
with large file system (LFS) support. */
32
#define PGM "pgp-import"
34
#include "t-support.h"
43
fputs ("usage: " PGM " [options] FILENAMEs\n\n"
45
" --verbose run in verbose mode\n"
46
" --url import from given URLs\n"
47
" -0 URLs are delimited by a nul\n"
53
main (int argc, char **argv)
60
gpgme_import_result_t impres;
65
while (argc && last_argc != argc )
68
if (!strcmp (*argv, "--"))
73
else if (!strcmp (*argv, "--help"))
75
else if (!strcmp (*argv, "--verbose"))
80
else if (!strcmp (*argv, "--url"))
85
else if (!strcmp (*argv, "-0"))
90
else if (!strncmp (*argv, "--", 2))
98
init_gpgme (GPGME_PROTOCOL_OpenPGP);
100
err = gpgme_new (&ctx);
102
gpgme_set_protocol (ctx, GPGME_PROTOCOL_OpenPGP);
104
for (; argc; argc--, argv++)
106
printf ("reading file `%s'\n", *argv);
107
err = gpgme_data_new_from_file (&data, *argv, 1);
111
gpgme_data_set_encoding (data, (nul_mode? GPGME_DATA_ENCODING_URL0
112
: GPGME_DATA_ENCODING_URL));
114
err = gpgme_op_import (ctx, data);
116
impres = gpgme_op_import_result (ctx);
119
fprintf (stderr, PGM ": no import result returned\n");
122
print_import_result (impres);
124
gpgme_data_release (data);