summaryrefslogtreecommitdiff
path: root/gpgscm
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2017-11-28 16:17:23 +0100
committerWerner Koch <wk@gnupg.org>2017-11-28 16:17:23 +0100
commit930d27ba6b1205395add0c79139e62355a1d5b62 (patch)
treece4212ea280360d05120828f14648ace60baa0c4 /gpgscm
parent4a2538e69dd35377bce0fb584f72322c69a111b3 (diff)
downloadlibgpg-error-930d27ba6b1205395add0c79139e62355a1d5b62.tar.gz
gpgscm: Some adjustments for use in gpgrt.
* gpgscm/Makefile.am: Remove cruft leftover from GnuPG. Link to the just build libgpg-error. * gpgscm/private.h: Include gpgrt.h and provide i18n macros. (xfree, xtrymalloc, xtrycalloc, xtryrealloc): New macros. (xmalloc, xstrdup): New inline functions. * gpgscm/main.c: Remove inclusion of gcrypt.h and gpg-error.h. Remove all other gnupg specific headers. (opts, parse_arguments): Temporary comment out. (main): Adjust for use with gpgrt. Temporary comment out some stuff. * gpgscm/ffi-private.h: Include local gpgrt.h instead of gpg-error.h. * gpgscm/ffi.h: Ditto. * gpgscm/ffi.c: Remove gpg-error.h and headers from GnuPG. (do_getenv): Use gpgrt_getenv. (do_setenv): Use gpgrt_setenv. (do_mkdtemp): Temporary return an error. (unlink_recursively): Use gpgrt_bsprintf. (do_getcwd): Use gpgrt_getcwd. (do_mkdir): Use gpgrt_mkdir. (do_get_isotime): Temporary return an error. (do_get_time): Directly use time(). -- Note that this does not yet compile because the spawn functions from GnuPG are missing. There are two other problems as well: - We don't have GnuPG's isotime fucntions. We need to see whether we want to support them in gpgrt. That might be useful in libksba. - gpgrt_mkdtemp does not work. We do not want to link to Libgcrypt, which is the way mkdtemp was written for GnuPG. We should get a more straight implementation. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'gpgscm')
-rw-r--r--gpgscm/Makefile.am17
-rw-r--r--gpgscm/ffi-private.h2
-rw-r--r--gpgscm/ffi.c32
-rw-r--r--gpgscm/ffi.h2
-rw-r--r--gpgscm/main.c116
-rw-r--r--gpgscm/private.h48
6 files changed, 127 insertions, 90 deletions
diff --git a/gpgscm/Makefile.am b/gpgscm/Makefile.am
index 59e1924..43741f2 100644
--- a/gpgscm/Makefile.am
+++ b/gpgscm/Makefile.am
@@ -31,9 +31,6 @@ EXTRA_DIST = \
gnupg.scm \
time.scm
-AM_CPPFLAGS = -I$(top_srcdir)/common
-include $(top_srcdir)/am/cmacros.am
-
AM_CFLAGS =
CLEANFILES =
@@ -41,23 +38,17 @@ CLEANFILES =
bin_PROGRAMS = gpgscm
noinst_PROGRAMS = t-child
-common_libs = ../$(libcommon)
-commonpth_libs = ../$(libcommonpth)
-
-gpgscm_CFLAGS = -imacros scheme-config.h \
- $(LIBGCRYPT_CFLAGS) $(LIBASSUAN_CFLAGS) $(GPG_ERROR_CFLAGS)
+gpgscm_CFLAGS = -imacros scheme-config.h
gpgscm_SOURCES = main.c private.h ffi.c ffi.h ffi-private.h \
scheme-config.h scheme.c scheme.h scheme-private.h \
opdefines.h small-integers.h
-gpgscm_LDADD = $(LDADD) $(common_libs) \
- $(NETLIBS) $(LIBICONV) $(LIBREADLINE) $(LIBINTL) \
- $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS)
+gpgscm_LDADD = $(LDADD) $(LIBREADLINE) ../src/libgpg-error.la $(LTLIBINTL)
t_child_SOURCES = t-child.c
# Make sure that all libs are build before we use them. This is
-# important for things like make -j2.
-$(PROGRAMS): $(common_libs)
+# important for parallel builds (i.e. make -j2).
+$(PROGRAMS): ../src/libgpg-error.la
check-local: gpgscm$(EXEEXT) t-child$(EXEEXT)
EXEEXT=$(EXEEXT) GPGSCM_PATH=$(srcdir) \
diff --git a/gpgscm/ffi-private.h b/gpgscm/ffi-private.h
index 5d82127..42627ea 100644
--- a/gpgscm/ffi-private.h
+++ b/gpgscm/ffi-private.h
@@ -20,7 +20,7 @@
#ifndef GPGSCM_FFI_PRIVATE_H
#define GPGSCM_FFI_PRIVATE_H
-#include <gpg-error.h>
+#include "../src/gpgrt.h"
#include "scheme.h"
#include "scheme-private.h"
diff --git a/gpgscm/ffi.c b/gpgscm/ffi.c
index 5c8ff45..51de63f 100644
--- a/gpgscm/ffi.c
+++ b/gpgscm/ffi.c
@@ -24,7 +24,6 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
-#include <gpg-error.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
@@ -40,9 +39,9 @@
#include <readline/history.h>
#endif
-#include "../../common/util.h"
-#include "../../common/exechelp.h"
-#include "../../common/sysutils.h"
+/* #include "../../common/util.h" */
+/* #include "../../common/exechelp.h" */
+/* #include "../../common/sysutils.h" */
#include "private.h"
#include "ffi.h"
@@ -236,7 +235,7 @@ do_getenv (scheme *sc, pointer args)
char *value;
FFI_ARG_OR_RETURN (sc, char *, name, string, args);
FFI_ARGS_DONE_OR_RETURN (sc, args);
- value = getenv (name);
+ value = gpgrt_getenv (name);
FFI_RETURN_STRING (sc, value ? value : "");
}
@@ -251,7 +250,7 @@ do_setenv (scheme *sc, pointer args)
FFI_ARG_OR_RETURN (sc, char *, value, string, args);
FFI_ARG_OR_RETURN (sc, int, overwrite, bool, args);
FFI_ARGS_DONE_OR_RETURN (sc, args);
- if (gnupg_setenv (name, value, overwrite))
+ if (gpgrt_setenv (name, value, overwrite))
FFI_RETURN_ERR (sc, gpg_error_from_syserror ());
FFI_RETURN (sc);
}
@@ -376,7 +375,7 @@ do_mkdtemp (scheme *sc, pointer args)
FFI_RETURN_ERR (sc, EINVAL);
strncpy (buffer, template, sizeof buffer);
- name = gnupg_mkdtemp (buffer);
+ name = NULL; /*gnupg_mkdtemp (buffer);*/
if (name == NULL)
FFI_RETURN_ERR (sc, gpg_error_from_syserror ());
FFI_RETURN_STRING (sc, name);
@@ -420,8 +419,8 @@ unlink_recursively (const char *name)
|| strcmp (dent->d_name, "..") == 0)
continue;
- child = xtryasprintf ("%s/%s", name, dent->d_name);
- if (child == NULL)
+ child = gpgrt_bsprintf ("%s/%s", name, dent->d_name);
+ if (!child)
{
err = gpg_error_from_syserror ();
goto leave;
@@ -479,7 +478,7 @@ do_getcwd (scheme *sc, pointer args)
pointer result;
char *cwd;
FFI_ARGS_DONE_OR_RETURN (sc, args);
- cwd = gnupg_getcwd ();
+ cwd = gpgrt_getcwd ();
if (cwd == NULL)
FFI_RETURN_ERR (sc, gpg_error_from_syserror ());
result = sc->vptr->mk_string (sc, cwd);
@@ -496,7 +495,7 @@ do_mkdir (scheme *sc, pointer args)
FFI_ARG_OR_RETURN (sc, char *, name, string, args);
FFI_ARG_OR_RETURN (sc, char *, mode, string, args);
FFI_ARGS_DONE_OR_RETURN (sc, args);
- if (gnupg_mkdir (name, mode) == -1)
+ if (gpgrt_mkdir (name, mode) == -1)
FFI_RETURN_ERR (sc, gpg_error_from_syserror ());
FFI_RETURN (sc);
}
@@ -517,9 +516,10 @@ static pointer
do_get_isotime (scheme *sc, pointer args)
{
FFI_PROLOG ();
- gnupg_isotime_t timebuf;
+ /* gnupg_isotime_t timebuf; */
+ char timebuf[15];
FFI_ARGS_DONE_OR_RETURN (sc, args);
- gnupg_get_isotime (timebuf);
+ *timebuf = 0; /*gnupg_get_isotime (timebuf);*/
FFI_RETURN_STRING (sc, timebuf);
}
@@ -527,8 +527,12 @@ static pointer
do_get_time (scheme *sc, pointer args)
{
FFI_PROLOG ();
+ time_t current;
FFI_ARGS_DONE_OR_RETURN (sc, args);
- FFI_RETURN_INT (sc, gnupg_get_time ());
+ current = time (NULL);
+ if (current == (time_t)(-1))
+ gpgrt_log_fatal ("time() failed\n");
+ FFI_RETURN_INT (sc, current);
}
static pointer
diff --git a/gpgscm/ffi.h b/gpgscm/ffi.h
index a7986e6..3ddf68b 100644
--- a/gpgscm/ffi.h
+++ b/gpgscm/ffi.h
@@ -20,7 +20,7 @@
#ifndef GPGSCM_FFI_H
#define GPGSCM_FFI_H
-#include <gpg-error.h>
+#include "../src/gpgrt.h"
#include "scheme.h"
gpg_error_t ffi_init (scheme *sc, const char *argv0, const char *scriptname,
diff --git a/gpgscm/main.c b/gpgscm/main.c
index a4963e2..22c7c98 100644
--- a/gpgscm/main.c
+++ b/gpgscm/main.c
@@ -23,8 +23,6 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <gcrypt.h>
-#include <gpg-error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -36,17 +34,12 @@
#include <sys/mman.h>
#endif
+
#include "private.h"
#include "scheme.h"
#include "scheme-private.h"
#include "ffi.h"
-#include "../common/i18n.h"
-#include "../../common/argparse.h"
-#include "../../common/init.h"
-#include "../../common/logging.h"
-#include "../../common/strlist.h"
-#include "../../common/sysutils.h"
-#include "../../common/util.h"
+
/* The TinyScheme banner. Unfortunately, it isn't in the header
file. */
@@ -64,35 +57,35 @@ enum cmd_and_opt_values
};
/* The list of commands and options. */
-static ARGPARSE_OPTS opts[] =
- {
- ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
- ARGPARSE_end (),
- };
+/* static ARGPARSE_OPTS opts[] = */
+/* { */
+/* ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")), */
+/* ARGPARSE_end (), */
+/* }; */
char *scmpath = "";
size_t scmpath_len = 0;
/* Command line parsing. */
-static void
-parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
-{
- int no_more_options = 0;
-
- while (!no_more_options && optfile_parse (NULL, NULL, NULL, pargs, popts))
- {
- switch (pargs->r_opt)
- {
- case oVerbose:
- verbose++;
- break;
-
- default:
- pargs->err = 2;
- break;
- }
- }
-}
+/* static void */
+/* parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts) */
+/* { */
+ /* int no_more_options = 0; */
+
+ /* while (!no_more_options && optfile_parse (NULL, NULL, NULL, pargs, popts)) */
+ /* { */
+ /* switch (pargs->r_opt) */
+ /* { */
+ /* case oVerbose: */
+ /* verbose++; */
+ /* break; */
+
+ /* default: */
+ /* pargs->err = 2; */
+ /* break; */
+ /* } */
+ /* } */
+/* } */
/* Print usage information and provide strings for help. */
static const char *
@@ -102,19 +95,18 @@ my_strusage( int level )
switch (level)
{
- case 11: p = "gpgscm (@GNUPG@)";
+ case 11: p = "gpgscm";
break;
case 13: p = VERSION; break;
- case 17: p = PRINTABLE_OS_NAME; break;
- case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
+ case 19: p = "Please report bugs to <@EMAIL@>.\n"; break;
case 1:
case 40:
- p = _("Usage: gpgscm [options] [file] (-h for help)");
+ p = "Usage: gpgscm [options] [file] (-h for help)";
break;
case 41:
- p = _("Syntax: gpgscm [options] [file]\n"
- "Execute the given Scheme program, or spawn interactive shell.\n");
+ p = "Syntax: gpgscm [options] [file]\n"
+ "Execute the given Scheme program, or spawn interactive shell.\n";
break;
default: p = NULL; break;
@@ -251,7 +243,7 @@ main (int argc, char **argv)
int retcode;
gpg_error_t err;
char *argv0;
- ARGPARSE_ARGS pargs;
+ /* ARGPARSE_ARGS pargs; */
scheme *sc;
char *p;
#if _WIN32
@@ -264,6 +256,13 @@ main (int argc, char **argv)
/* Save argv[0] so that we can re-exec. */
argv0 = argv[0];
+ if (!gpgrt_check_version (PACKAGE_VERSION))
+ {
+ fprintf (stderr, _("%s is too old (need %s, have %s)\n"), "libgpg-error",
+ PACKAGE_VERSION, gpgrt_check_version (NULL));
+ exit (2);
+ }
+
/* Parse path. */
if (getenv ("GPGSCM_PATH"))
scmpath = getenv ("GPGSCM_PATH");
@@ -278,33 +277,28 @@ main (int argc, char **argv)
if (*p == pathsep)
*p = 0, scmpath_len++;
- set_strusage (my_strusage);
- log_set_prefix ("gpgscm", GPGRT_LOG_WITH_PREFIX);
+ /* set_strusage (my_strusage); */
+ gpgrt_log_set_prefix ("gpgscm", GPGRT_LOG_WITH_PREFIX);
/* Make sure that our subsystems are ready. */
- i18n_init ();
- init_common_subsystems (&argc, &argv);
-
- if (!gcry_check_version (NEED_LIBGCRYPT_VERSION))
- {
- fputs ("libgcrypt version mismatch\n", stderr);
- exit (2);
- }
+ /* i18n_init (); */
+ /* init_common_subsystems (&argc, &argv); */
/* Parse the command line. */
- pargs.argc = &argc;
- pargs.argv = &argv;
- pargs.flags = 0;
- parse_arguments (&pargs, opts);
+ /* pargs.argc = &argc; */
+ /* pargs.argv = &argv; */
+ /* pargs.flags = 0; */
+ /* parse_arguments (&pargs, opts); */
- if (log_get_errorcount (0))
+ if (gpgrt_get_errorcount (0))
exit (2);
- sc = scheme_init_new_custom_alloc (gcry_malloc, gcry_free);
- if (! sc) {
- fprintf (stderr, "Could not initialize TinyScheme!\n");
- return 2;
- }
+ sc = scheme_init_new_custom_alloc (gpgrt_malloc, gpgrt_free);
+ if (!sc)
+ {
+ fprintf (stderr, "Could not initialize TinyScheme!\n");
+ return 2;
+ }
scheme_set_input_port_file (sc, stdin);
scheme_set_output_port_file (sc, stderr);
@@ -347,7 +341,7 @@ main (int argc, char **argv)
{
err = load (sc, script, 1, 1);
if (err)
- log_fatal ("%s: %s", script, gpg_strerror (err));
+ gpgrt_log_fatal ("%s: %s", script, gpg_strerror (err));
}
retcode = sc->retcode;
diff --git a/gpgscm/private.h b/gpgscm/private.h
index 5685314..93547ce 100644
--- a/gpgscm/private.h
+++ b/gpgscm/private.h
@@ -20,6 +20,54 @@
#ifndef GPGSCM_PRIVATE_H
#define GPGSCM_PRIVATE_H
+
+#include "../src/gpgrt.h"
+
+/*
+ * Internal i18n macros.
+ */
+#ifdef ENABLE_NLS
+# ifdef HAVE_W32_SYSTEM
+# include "gettext.h"
+# else
+# include <libintl.h>
+# endif
+# define _(a) gettext (a)
+# ifdef gettext_noop
+# define N_(a) gettext_noop (a)
+# else
+# define N_(a) (a)
+# endif
+#else /*!ENABLE_NLS*/
+# define _(a) (a)
+# define N_(a) (a)
+#endif /*!ENABLE_NLS */
+
+#define xfree(a) gpgrt_free ((a))
+#define xtrymalloc(a) gpgrt_malloc ((a))
+#define xtrycalloc(a,b) gpgrt_calloc ((a),(b))
+#define xtryrealloc(a,b) gpgrt_realloc ((a),(b))
+
+
+static GPGRT_INLINE void *
+xmalloc (size_t n)
+{
+ void *p = gpgrt_malloc (n);
+ if (!p)
+ log_fatal ("malloc failed: %s\n", strerror (errno));
+ return p;
+}
+
+static GPGRT_INLINE char *
+xstrdup (const char *s)
+{
+ char *p = gpgrt_malloc (strlen (s) + 1);
+ strcpy (p, s);
+ return p;
+}
+
+
extern int verbose;
+
#endif /* GPGSCM_PRIVATE_H */