aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2001-11-20 06:04:15 +0000
committerMarcus Brinkmann <[email protected]>2001-11-20 06:04:15 +0000
commit38c00b4b323eaccf130e6d06cce5a55c1201584f (patch)
tree5d42f26301c804d9d01505a0331e94e41a8efd92
parentremove some CVS conflict cruft (diff)
downloadgpgme-38c00b4b323eaccf130e6d06cce5a55c1201584f.tar.gz
gpgme-38c00b4b323eaccf130e6d06cce5a55c1201584f.zip
2001-11-20 Marcus Brinkmann <[email protected]>
* types.h: Add types EngineObject and GpgsmObject. * Makefile.am (libgpgme_la_SOURCES): Add engine-gpgsm.h, engine-gpgsm.c, engine.h and engine.c. * engine.h: New file. * engine.c: Likewise. * engine-gpgsm.h: Likewise. * engine-gpgsm.c: Likewise. * rungpg.c (_gpgme_gpg_get_version): New function. (_gpgme_gpg_check_version): Likewise. * rungpg.h: Add prototypes for _gpgme_gpg_get_version and _gpgme_gpg_check_version. * version.c (compare_versions): Rename to ... (_gpgme_compare_versions): ... this. Make non-static. (gpgme_check_version): Use _gpgme_compare_versions rather than compare_versions. (gpgme_check_engine): Likewise. * ops.h (_gpgme_get_program_version): Add prototype.
Diffstat (limited to '')
-rw-r--r--gpgme/engine-gpgsm.c130
-rw-r--r--gpgme/engine-gpgsm.h33
-rw-r--r--gpgme/engine.c157
-rw-r--r--gpgme/engine.h32
4 files changed, 352 insertions, 0 deletions
diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c
new file mode 100644
index 00000000..000ad116
--- /dev/null
+++ b/gpgme/engine-gpgsm.c
@@ -0,0 +1,130 @@
+/* engine-gpgsm.c - GpgSM engine
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ * Copyright (C) 2001 g10 Code GmbH
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gpgme.h"
+#include "util.h"
+#include "types.h"
+#include "ops.h"
+
+#include "engine-gpgsm.h"
+
+/* FIXME: Correct check? */
+#ifdef GPGSM_PATH
+#define ENABLE_GPGSM 1
+#endif
+
+#ifdef ENABLE_GPGSM
+
+#include "assuan.h"
+
+struct gpgsm_object_s
+{
+ ASSUAN_CONTEXT assuan_ctx;
+};
+
+const char *
+_gpgme_gpgsm_get_version (void)
+{
+ static const char *gpgsm_version;
+
+ /* FIXME: Locking. */
+ if (!gpgsm_version)
+ gpgsm_version = _gpgme_get_program_version (_gpgme_get_gpgsm_path ());
+
+ return gpgsm_version;
+}
+
+GpgmeError
+_gpgme_gpgsm_check_version (void)
+{
+ return _gpgme_compare_versions (_gpgme_gpgsm_get_version (),
+ NEED_GPGSM_VERSION)
+ ? 0 : mk_error (Invalid_Engine);
+}
+
+GpgmeError
+_gpgme_gpgsm_new (GpgsmObject *r_gpgsm)
+{
+ GpgmeError err = 0;
+ GpgsmObject gpgsm;
+ char *argv[] = { "gpgsm", "--server", NULL };
+
+ *r_gpgsm = NULL;
+ gpgsm = xtrycalloc (1, sizeof *gpgsm);
+ if (!gpgsm)
+ {
+ err = mk_error (Out_Of_Core);
+ goto leave;
+ }
+
+ err = assuan_pipe_connect (&gpgsm->assuan_ctx,
+ _gpgme_get_gpgsm_path (), argv);
+
+ leave:
+ if (err)
+ _gpgme_gpgsm_release (gpgsm);
+ else
+ *r_gpgsm = gpgsm;
+
+ return err;
+}
+
+void
+_gpgme_gpgsm_release (GpgsmObject gpgsm)
+{
+ if (!gpgsm)
+ return;
+
+ assuan_pipe_disconnect (gpgsm->assuan_ctx);
+ xfree (gpgsm);
+}
+
+#else /* ENABLE_GPGSM */
+
+const char *
+_gpgme_gpgsm_get_version (void)
+{
+ return NULL;
+}
+
+GpgmeError
+_gpgme_gpgsm_check_version (void)
+{
+ return mk_error (Invalid_Engine);
+}
+
+GpgmeError
+_gpgme_gpgsm_new (GpgsmObject *r_gpgsm)
+{
+ return mk_error (Invalid_Engine);
+}
+
+void
+_gpgme_gpgsm_release (GpgsmObject gpgsm)
+{
+ return;
+}
+
+#endif /* ! ENABLE_GPGSM */
diff --git a/gpgme/engine-gpgsm.h b/gpgme/engine-gpgsm.h
new file mode 100644
index 00000000..105405bd
--- /dev/null
+++ b/gpgme/engine-gpgsm.h
@@ -0,0 +1,33 @@
+/* engine-gpgsm.h - GPGME GpgSM engine calling functions
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ * Copyright (C) 2001 g10 Code GmbH
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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 ENGINE_GPGSM_H
+#define ENGINE_GPGSM_H
+
+#include "types.h"
+
+const char *_gpgme_gpgsm_get_version (void);
+GpgmeError _gpgme_gpgsm_check_version (void);
+
+GpgmeError _gpgme_gpgsm_new (GpgsmObject *r_gpg);
+void _gpgme_gpgsm_release (GpgsmObject gpg);
+
+#endif /* ENGINE_GPGSM_H */
diff --git a/gpgme/engine.c b/gpgme/engine.c
new file mode 100644
index 00000000..0485fb9b
--- /dev/null
+++ b/gpgme/engine.c
@@ -0,0 +1,157 @@
+/* engine.c
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ * Copyright (C) 2001 g10 Code GmbH
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gpgme.h"
+#include "util.h"
+
+#include "engine.h"
+#include "rungpg.h"
+#include "engine-gpgsm.h"
+
+struct engine_object_s
+ {
+ GpgmeProtocol protocol;
+
+ const char *path;
+ const char *version;
+
+ union
+ {
+ GpgObject gpg;
+ GpgsmObject gpgsm;
+ } engine;
+};
+
+/* Get the path of the engine for PROTOCOL. */
+const char *
+_gpgme_engine_get_path (GpgmeProtocol proto)
+{
+ switch (proto)
+ {
+ case GPGME_PROTOCOL_OpenPGP:
+ return _gpgme_get_gpg_path ();
+ case GPGME_PROTOCOL_CMS:
+ return _gpgme_get_gpgsm_path ();
+ default:
+ return NULL;
+ }
+}
+
+/* Get the version number of the engine for PROTOCOL. */
+const char *
+_gpgme_engine_get_version (GpgmeProtocol proto)
+{
+ switch (proto)
+ {
+ case GPGME_PROTOCOL_OpenPGP:
+ return _gpgme_gpg_get_version ();
+ case GPGME_PROTOCOL_CMS:
+ return _gpgme_gpgsm_get_version ();
+ default:
+ return NULL;
+ }
+}
+
+GpgmeError
+gpgme_engine_check_version (GpgmeProtocol proto)
+{
+ switch (proto)
+ {
+ case GPGME_PROTOCOL_OpenPGP:
+ return _gpgme_gpg_check_version ();
+ case GPGME_PROTOCOL_CMS:
+ return _gpgme_gpgsm_check_version ();
+ default:
+ return mk_error (Invalid_Value);
+ }
+}
+
+GpgmeError
+_gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine)
+{
+ EngineObject engine;
+ GpgmeError err = 0;
+
+ engine = xtrycalloc (1, sizeof *engine);
+ if (!engine)
+ {
+ err = mk_error (Out_Of_Core);
+ goto leave;
+ }
+
+ engine->protocol = proto;
+ switch (proto)
+ {
+ case GPGME_PROTOCOL_OpenPGP:
+ err =_gpgme_gpg_new (&engine->engine.gpg);
+ break;
+ case GPGME_PROTOCOL_CMS:
+ err = _gpgme_gpgsm_new (&engine->engine.gpgsm);
+ if (err)
+ goto leave;
+ break;
+ default:
+ err = mk_error (Invalid_Value);
+ }
+ if (err)
+ goto leave;
+
+ engine->path = _gpgme_engine_get_path (proto);
+ engine->version = _gpgme_engine_get_version (proto);
+
+ if (!engine->path || !engine->version)
+ {
+ err = mk_error (Invalid_Engine);
+ goto leave;
+ }
+
+ leave:
+ if (err)
+ _gpgme_engine_release (engine);
+ else
+ *r_engine = engine;
+
+ return err;
+}
+
+void
+_gpgme_engine_release (EngineObject engine)
+{
+ if (!engine)
+ return;
+
+ switch (engine->protocol)
+ {
+ case GPGME_PROTOCOL_OpenPGP:
+ _gpgme_gpg_release (engine->engine.gpg);
+ break;
+ case GPGME_PROTOCOL_CMS:
+ _gpgme_gpgsm_release (engine->engine.gpgsm);
+ break;
+ default:
+ break;
+ }
+ xfree (engine);
+}
diff --git a/gpgme/engine.h b/gpgme/engine.h
new file mode 100644
index 00000000..372128b7
--- /dev/null
+++ b/gpgme/engine.h
@@ -0,0 +1,32 @@
+/* engine.h - GPGME engine calling functions
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ * Copyright (C) 2001 g10 Code GmbH
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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 ENGINE_H
+#define ENGINE_H
+
+#include "types.h"
+
+const char *_gpgme_engine_get_path (GpgmeProtocol proto);
+const char *_gpgme_engine_get_version (GpgmeProtocol proto);
+GpgmeError _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine);
+void _gpgme_engine_release (EngineObject engine);
+
+#endif /* ENGINE_H */