2001-11-20 Marcus Brinkmann <marcus@g10code.de>
* 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.
This commit is contained in:
parent
4d3ab72fe5
commit
38c00b4b32
130
gpgme/engine-gpgsm.c
Normal file
130
gpgme/engine-gpgsm.c
Normal file
@ -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 */
|
33
gpgme/engine-gpgsm.h
Normal file
33
gpgme/engine-gpgsm.h
Normal file
@ -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 */
|
157
gpgme/engine.c
Normal file
157
gpgme/engine.c
Normal file
@ -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);
|
||||
}
|
32
gpgme/engine.h
Normal file
32
gpgme/engine.h
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user