aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2001-11-24 17:43:43 +0000
committerWerner Koch <[email protected]>2001-11-24 17:43:43 +0000
commitbab7fa0b297b8e99f5e222bbceda0716b62f7215 (patch)
treeb3fe5f7ec7e1c1bed0bdd98f036c27d605106d15 /common
parentSigning does now work. There is no secret key management yet, so you (diff)
downloadgnupg-bab7fa0b297b8e99f5e222bbceda0716b62f7215.tar.gz
gnupg-bab7fa0b297b8e99f5e222bbceda0716b62f7215.zip
Added new directory common to enable sharing of some code and error
numbers between gpg, gpgsm and gpg-agent. Move some files and code to there.
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am35
-rw-r--r--common/README14
-rw-r--r--common/errors.h122
-rw-r--r--common/i18n.h47
-rw-r--r--common/maperror.c85
-rwxr-xr-xcommon/mkerrors72
-rw-r--r--common/util.h59
7 files changed, 434 insertions, 0 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
new file mode 100644
index 000000000..3c5e47119
--- /dev/null
+++ b/common/Makefile.am
@@ -0,0 +1,35 @@
+# Makefile for common gnupg modules
+# Copyright (C) 2001 Free Software Foundation, Inc.
+#
+# This file is part of GnuPG.
+#
+# GnuPG is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GnuPG is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+## Process this file with automake to produce Makefile.in
+
+EXTRA_DIST = mkerrors
+#INCLUDES =
+BUILT_SOURCES = errors.c
+
+noinst_LIBRARIES = libcommon.a
+
+libcommon_a_SOURCES = \
+ util.h i18n.h \
+ errors.c errors.h \
+ maperror.c
+
+
+errors.c : errors.h mkerrors
+ $(srcdir)/mkerrors < $(srcdir)/errors.h > errors.c
diff --git a/common/README b/common/README
new file mode 100644
index 000000000..d3927d869
--- /dev/null
+++ b/common/README
@@ -0,0 +1,14 @@
+Stuff used by several modules of GnuPG. This way we can share error
+codes and serveral other things.
+
+
+These directories use it:
+
+gpg
+sm
+agent
+
+These directories don't use it:
+
+assuan
+kbx \ No newline at end of file
diff --git a/common/errors.h b/common/errors.h
new file mode 100644
index 000000000..4f7cb32f0
--- /dev/null
+++ b/common/errors.h
@@ -0,0 +1,122 @@
+/* errors.h - Globally used error codes
+ * Copyright (C) 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef GNUPG_COMMON_ERRORS_H
+#define GNUPG_COMMON_ERRORS_H
+
+#include "util.h"
+
+/* Error numbers */
+enum {
+ GNUPG_EOF = -1,
+ GNUPG_No_Error = 0,
+ GNUPG_General_Error = 1,
+ GNUPG_Out_Of_Core = 2,
+ GNUPG_Invalid_Value = 3,
+ GNUPG_IO_Error = 4,
+ GNUPG_Resource_Limit = 5,
+ GNUPG_Internal_Error = 6,
+ GNUPG_Bad_Certificate = 7,
+ GNUPG_Bad_Certificate_Path = 8,
+ GNUPG_Missing_Certificate = 9,
+ GNUPG_No_Data = 10,
+ GNUPG_Bad_Signature = 11,
+ GNUPG_Not_Implemented = 12,
+ GNUPG_Conflict = 13,
+ GNUPG_Bug = 14
+};
+
+/* Status codes - fixme: should go into another file */
+enum {
+ STATUS_ENTER,
+ STATUS_LEAVE,
+ STATUS_ABORT,
+ STATUS_GOODSIG,
+ STATUS_BADSIG,
+ STATUS_ERRSIG,
+ STATUS_BADARMOR,
+ STATUS_RSA_OR_IDEA,
+ STATUS_SIGEXPIRED,
+ STATUS_KEYREVOKED,
+ STATUS_TRUST_UNDEFINED,
+ STATUS_TRUST_NEVER,
+ STATUS_TRUST_MARGINAL,
+ STATUS_TRUST_FULLY,
+ STATUS_TRUST_ULTIMATE,
+
+ STATUS_SHM_INFO,
+ STATUS_SHM_GET,
+ STATUS_SHM_GET_BOOL,
+ STATUS_SHM_GET_HIDDEN,
+
+ STATUS_NEED_PASSPHRASE,
+ STATUS_VALIDSIG,
+ STATUS_SIG_ID,
+ STATUS_ENC_TO,
+ STATUS_NODATA,
+ STATUS_BAD_PASSPHRASE,
+ STATUS_NO_PUBKEY,
+ STATUS_NO_SECKEY,
+ STATUS_NEED_PASSPHRASE_SYM,
+ STATUS_DECRYPTION_FAILED,
+ STATUS_DECRYPTION_OKAY,
+ STATUS_MISSING_PASSPHRASE,
+ STATUS_GOOD_PASSPHRASE,
+ STATUS_GOODMDC,
+ STATUS_BADMDC,
+ STATUS_ERRMDC,
+ STATUS_IMPORTED,
+ STATUS_IMPORT_RES,
+ STATUS_FILE_START,
+ STATUS_FILE_DONE,
+ STATUS_FILE_ERROR,
+
+ STATUS_BEGIN_DECRYPTION,
+ STATUS_END_DECRYPTION,
+ STATUS_BEGIN_ENCRYPTION,
+ STATUS_END_ENCRYPTION,
+
+ STATUS_DELETE_PROBLEM,
+ STATUS_GET_BOOL,
+ STATUS_GET_LINE,
+ STATUS_GET_HIDDEN,
+ STATUS_GOT_IT,
+ STATUS_PROGRESS,
+ STATUS_SIG_CREATED,
+ STATUS_SESSION_KEY,
+ STATUS_NOTATION_NAME,
+ STATUS_NOTATION_DATA,
+ STATUS_POLICY_URL,
+ STATUS_BEGIN_STREAM,
+ STATUS_END_STREAM,
+ STATUS_KEY_CREATED,
+ STATUS_USERID_HIN,
+ STATUS_UNEXPECTED,
+ STATUS_INV_RECP,
+ STATUS_NO_RECP,
+ STATUS_ALREADY_SIGNED,
+};
+
+
+/*-- errors.c (built) --*/
+const char *gnupg_strerror (int err);
+
+
+#endif /*GNUPG_COMMON_ERRORS_H*/
diff --git a/common/i18n.h b/common/i18n.h
new file mode 100644
index 000000000..0e13dca4d
--- /dev/null
+++ b/common/i18n.h
@@ -0,0 +1,47 @@
+/* i18n.h
+ * Copyright (C) 1998, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef GNUPG_COMMON_I18N_H
+#define GNUPG_COMMON_I18N_H
+
+#ifdef USE_SIMPLE_GETTEXT
+ int set_gettext_file( const char *filename );
+ const char *gettext( const char *msgid );
+# define _(a) gettext (a)
+# define N_(a) (a)
+#else
+# ifdef HAVE_LOCALE_H
+# include <locale.h>
+# endif
+# ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(a) gettext (a)
+# ifdef gettext_noop
+# define N_(a) gettext_noop (a)
+# else
+# define N_(a) (a)
+# endif
+# else
+# define _(a) (a)
+# define N_(a) (a)
+# endif
+#endif /*!USE_SIMPLE_GETTEXT*/
+
+#endif /*GNUPG_COMMON_I18N_H*/
diff --git a/common/maperror.c b/common/maperror.c
new file mode 100644
index 000000000..894e235ca
--- /dev/null
+++ b/common/maperror.c
@@ -0,0 +1,85 @@
+/* maperror.c - Error mapping
+ * Copyright (C) 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <config.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include <ksba.h>
+
+#include "util.h"
+#include "errors.h"
+
+
+/* Note: we might want to wrap this in a macro to get our hands on
+ the line and file where the error occired */
+int
+map_ksba_err (int err)
+{
+ switch (err)
+ {
+ case -1:
+ case 0:
+ break;
+
+ default:
+ err = seterr (General_Error);
+ break;
+ }
+ return err;
+}
+
+
+int
+map_gcry_err (int err)
+{
+ switch (err)
+ {
+ case -1:
+ case 0:
+ break;
+
+ default:
+ err = seterr (General_Error);
+ break;
+ }
+ return err;
+}
+
+int
+map_kbx_err (int err)
+{
+ switch (err)
+ {
+ case -1:
+ case 0:
+ break;
+
+ default:
+ err = seterr (General_Error);
+ break;
+ }
+ return err;
+}
+
diff --git a/common/mkerrors b/common/mkerrors
new file mode 100755
index 000000000..5a1ef33da
--- /dev/null
+++ b/common/mkerrors
@@ -0,0 +1,72 @@
+#!/bin/sh
+# mkerrors - Extract error strings from errors.h
+# and create C source for gnupg_strerror
+# Copyright (C) 2001 Free Software Foundation, Inc.
+#
+# This file is part of GnuPG.
+#
+# GnuPG is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GnuPG is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+cat <<EOF
+/* Generated automatically by mkerrors */
+/* Do not edit! */
+
+#include <config.h>
+#include <stdio.h>
+#include "errors.h"
+
+/**
+ * gnupg_strerror:
+ * @err: Error code
+ *
+ * This function returns a textual representaion of the given
+ * errorcode. If this is an unknown value, a string with the value
+ * is returned (Beware: it is hold in a static buffer).
+ *
+ * Return value: String with the error description.
+ **/
+const char *
+gnupg_strerror (int err)
+{
+ const char *s;
+ static char buf[25];
+
+ switch (err)
+ {
+EOF
+
+awk '
+/GNUPG_No_Error/ { okay=1 }
+!okay {next}
+/}/ { exit 0 }
+/GNUPG_[A-Za-z_]*/ { print_code($1) }
+
+
+function print_code( s )
+{
+printf " case %s: s=\"", s ;
+gsub(/_/, " ", s );
+printf "%s\"; break;\n", tolower(substr(s,7));
+}
+'
+
+cat <<EOF
+ default: sprintf (buf, "ec=%d", err ); s=buf; break;
+ }
+
+ return s;
+}
+
+EOF \ No newline at end of file
diff --git a/common/util.h b/common/util.h
new file mode 100644
index 000000000..478d851eb
--- /dev/null
+++ b/common/util.h
@@ -0,0 +1,59 @@
+/* util.h - Utility functions for Gnupg
+ * Copyright (C) 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef GNUPG_COMMON_UTIL_H
+#define GNUPG_COMMON_UTIL_H
+
+#include <gcrypt.h> /* we need this for the memory function protos */
+
+/* to pass hash functions to libksba we need to cast it */
+#define HASH_FNC ((void (*)(void *, const void*,size_t))gcry_md_write)
+
+/* get all the stuff from jnlib */
+#include "../jnlib/logging.h"
+#include "../jnlib/argparse.h"
+#include "../jnlib/stringhelp.h"
+#include "../jnlib/mischelp.h"
+#include "../jnlib/strlist.h"
+#include "../jnlib/dotlock.h"
+
+/* handy malloc macros - use only them */
+#define xtrymalloc(a) gcry_malloc ((a))
+#define xtrycalloc(a,b) gcry_calloc ((a),(b))
+#define xtryrealloc(a,b) gcry_realloc ((a),(b))
+#define xtrystrdup(a) gcry_strdup ((a))
+#define xfree(a) gcry_free ((a))
+
+#define xmalloc(a) gcry_xmalloc ((a))
+#define xcalloc(a,b) gcry_xcalloc ((a),(b))
+#define xrealloc(a,b) gcry_xrealloc ((a),(b))
+#define xstrdup(a) gcry_xstrdup ((a))
+
+#define seterr(a) (GNUPG_ ## a)
+
+/*-- maperror.c --*/
+int map_ksba_err (int err);
+int map_gcry_err (int err);
+int map_kbx_err (int err);
+
+
+#endif /*GNUPG_COMMON_UTIL_H*/
+
+