Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34388845
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
21 KB
Subscribers
None
View Options
diff --git a/editinteractor.cpp b/editinteractor.cpp
index 24f9b0ff..d22553c8 100644
--- a/editinteractor.cpp
+++ b/editinteractor.cpp
@@ -1,155 +1,167 @@
/*
editinteractor.cpp - Interface for edit interactors
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "editinteractor.h"
#include "callbacks.h"
#include "error.h"
#include <gpg-error.h>
#ifdef _WIN32
# include <io.h>
# define write _write
#else
# include <unistd.h>
#endif
#include <cstring>
using namespace GpgME;
class EditInteractor::Private {
friend class ::GpgME::EditInteractor;
friend class ::GpgME::CallbackHelper;
EditInteractor * const q;
public:
explicit Private( EditInteractor * qq );
~Private();
private:
unsigned int state;
Error error;
std::FILE * debug;
};
class GpgME::CallbackHelper {
public:
static int edit_interactor_callback_impl( void * opaque, gpgme_status_code_t status, const char * args, int fd ) {
EditInteractor::Private * ei = (EditInteractor::Private*)opaque;
- try {
+ Error err;
+
// advance to next state based on input:
const unsigned int oldState = ei->state;
- ei->state = ei->q->nextState( status, args );
+ ei->state = ei->q->nextState( status, args, err );
+ if ( err ) {
+ ei->state = oldState;
+ goto error;
+ }
if ( ei->debug )
std::fprintf( ei->debug, "EditInteractor: %u -> nextState( %u, %s ) -> %u\n",
oldState, (unsigned int)status, args ? args : "<null>", ei->state );
if ( ei->state != oldState &&
// if there was an error from before, we stop here (### this looks weird, can this happen at all?)
gpg_err_code( ei->error.code() ) == GPG_ERR_NO_ERROR ) {
// successful state change -> call action
- if ( const char * const result = ei->q->action() ) {
+ if ( const char * const result = ei->q->action( err ) ) {
+ if ( err )
+ goto error;
if ( ei->debug )
std::fprintf( ei->debug, "EditInteractor: action result \"%s\"\n", result );
// if there's a result, write it:
if ( *result )
write( fd, result, std::strlen( result ) );
write( fd, "\n", 1 );
} else {
+ if ( err )
+ goto error;
if ( ei->debug )
std::fprintf( ei->debug, "EditInteractor: no action result\n" );
}
} else {
if ( ei->debug )
std::fprintf( ei->debug, "EditInteractor: no action executed\n" );
}
- } catch ( const Error & err ) {
+
+ error:
+ if ( err ) {
ei->error = err;
ei->state = EditInteractor::ErrorState;
}
if ( ei->debug )
std::fprintf( ei->debug, "EditInteractor: error now %u (%s)\n",
ei->error.encodedError(), gpg_strerror( ei->error.encodedError() ) );
return ei->error.encodedError();
}
};
static gpgme_error_t edit_interactor_callback( void * opaque, gpgme_status_code_t status, const char * args, int fd )
{
return CallbackHelper::edit_interactor_callback_impl( opaque, status, args, fd );
}
gpgme_edit_cb_t GpgME::edit_interactor_callback = ::edit_interactor_callback;
EditInteractor::Private::Private( EditInteractor * qq )
: q( qq ),
state( StartState ),
- error()
+ error(),
+ debug(0)
{
}
EditInteractor::Private::~Private() {}
EditInteractor::EditInteractor()
: d( new Private( this ) )
{
}
EditInteractor::~EditInteractor() {
delete d; d = 0;
}
unsigned int EditInteractor::state() const {
return d->state;
}
Error EditInteractor::lastError() const {
return d->error;
}
bool EditInteractor::needsNoResponse( unsigned int status ) const {
switch ( status ) {
case GPGME_STATUS_EOF:
case GPGME_STATUS_GOT_IT:
case GPGME_STATUS_NEED_PASSPHRASE:
case GPGME_STATUS_NEED_PASSPHRASE_SYM:
case GPGME_STATUS_GOOD_PASSPHRASE:
case GPGME_STATUS_BAD_PASSPHRASE:
case GPGME_STATUS_USERID_HINT:
case GPGME_STATUS_SIGEXPIRED:
case GPGME_STATUS_KEYEXPIRED:
return true;
default:
return false;
}
}
void EditInteractor::setDebugChannel( std::FILE * debug ) {
d->debug = debug;
}
diff --git a/editinteractor.h b/editinteractor.h
index 05fb7abe..2e7858b8 100644
--- a/editinteractor.h
+++ b/editinteractor.h
@@ -1,66 +1,66 @@
/*
editinteractor.h - Interface for edit interactors
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GPGMEPP_EDITINTERACTOR_H__
#define __GPGMEPP_EDITINTERACTOR_H__
#include <gpgme++/gpgme++_export.h>
#include <cstdio>
namespace GpgME {
class Error;
class Context;
class CallbackHelper;
class GPGMEPP_EXPORT EditInteractor {
friend class ::GpgME::Context;
friend class ::GpgME::CallbackHelper;
EditInteractor( const EditInteractor & );
EditInteractor & operator=( const EditInteractor & );
public:
EditInteractor();
virtual ~EditInteractor();
enum {
StartState = 0,
ErrorState = 0xFFFFFFFF
};
- virtual const char * action() const = 0;
- virtual unsigned int nextState( unsigned int statusCode, const char * args ) const = 0;
+ virtual const char * action( Error & err ) const = 0;
+ virtual unsigned int nextState( unsigned int statusCode, const char * args, Error & err ) const = 0;
unsigned int state() const;
Error lastError() const;
bool needsNoResponse( unsigned int statusCode ) const;
void setDebugChannel( std::FILE * file );
private:
class Private;
Private * d;
};
} // namespace GpgME
#endif // __GPGMEPP_EDITINTERACTOR_H__
diff --git a/gpgsetexpirytimeeditinteractor.cpp b/gpgsetexpirytimeeditinteractor.cpp
index 91106f68..7bdabf52 100644
--- a/gpgsetexpirytimeeditinteractor.cpp
+++ b/gpgsetexpirytimeeditinteractor.cpp
@@ -1,129 +1,133 @@
/*
gpgsetexpirytimeeditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "gpgsetexpirytimeeditinteractor.h"
#include "error.h"
#include <gpgme.h>
#include <cstring>
using std::strcmp;
// avoid conflict (msvc)
#ifdef ERROR
# undef ERROR
#endif
using namespace GpgME;
GpgSetExpiryTimeEditInteractor::GpgSetExpiryTimeEditInteractor( const std::string & t )
: EditInteractor(),
m_strtime( t )
{
}
GpgSetExpiryTimeEditInteractor::~GpgSetExpiryTimeEditInteractor() {}
// work around --enable-final
namespace GpgSetExpiryTimeEditInteractor_Private {
enum {
START = EditInteractor::StartState,
COMMAND,
DATE,
QUIT,
SAVE,
ERROR = EditInteractor::ErrorState
};
}
-const char * GpgSetExpiryTimeEditInteractor::action() const {
+const char * GpgSetExpiryTimeEditInteractor::action( Error & err ) const {
using namespace GpgSetExpiryTimeEditInteractor_Private;
switch ( state() ) {
case COMMAND:
return "expire";
case DATE:
return m_strtime.c_str();
case QUIT:
return "quit";
case SAVE:
return "Y";
case START:
case ERROR:
return 0;
default:
- throw Error( gpg_error( GPG_ERR_GENERAL ) );
+ err = Error( gpg_error( GPG_ERR_GENERAL ) );
+ return 0;
}
}
-unsigned int GpgSetExpiryTimeEditInteractor::nextState( unsigned int status, const char * args ) const {
+unsigned int GpgSetExpiryTimeEditInteractor::nextState( unsigned int status, const char * args, Error & err ) const {
static const Error GENERAL_ERROR( gpg_error( GPG_ERR_GENERAL ) );
static const Error INV_TIME_ERROR( gpg_error( GPG_ERR_INV_TIME ) );
if ( needsNoResponse( status ) )
return state();
using namespace GpgSetExpiryTimeEditInteractor_Private;
switch ( state() ) {
case START:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return COMMAND;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case COMMAND:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keygen.valid" ) == 0 )
return DATE;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case DATE:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return QUIT;
else if ( status == GPGME_STATUS_GET_LINE &&
- strcmp( args, "keygen.valid" ) )
- throw INV_TIME_ERROR;
- else
- throw GENERAL_ERROR;
+ strcmp( args, "keygen.valid" ) ) {
+ err = INV_TIME_ERROR;
+ return ERROR;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
case QUIT:
if ( status == GPGME_STATUS_GET_BOOL &&
strcmp( args, "keyedit.save.okay" ) == 0 )
return SAVE;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case ERROR:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return QUIT;
- else
- throw lastError();
+ err = lastError();
+ return ERROR;
default:
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
};
}
diff --git a/gpgsetexpirytimeeditinteractor.h b/gpgsetexpirytimeeditinteractor.h
index ac5e3547..37806f5f 100644
--- a/gpgsetexpirytimeeditinteractor.h
+++ b/gpgsetexpirytimeeditinteractor.h
@@ -1,47 +1,47 @@
/*
gpgsetexpirytimeeditinteractor.h - Edit Interactor to change the expiry time of an OpenPGP key
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__
#define __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__
#include <gpgme++/editinteractor.h>
#include <string>
namespace GpgME {
class GPGMEPP_EXPORT GpgSetExpiryTimeEditInteractor : public EditInteractor {
public:
explicit GpgSetExpiryTimeEditInteractor( const std::string & timeString="0" );
~GpgSetExpiryTimeEditInteractor();
private:
- /* reimp */ const char * action() const;
- /* reimp */ unsigned int nextState( unsigned int statusCode, const char * args ) const;
+ /* reimp */ const char * action( Error & err ) const;
+ /* reimp */ unsigned int nextState( unsigned int statusCode, const char * args, Error & err ) const;
private:
const std::string m_strtime;
};
} // namespace GpgME
#endif // __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H___
diff --git a/gpgsetownertrusteditinteractor.cpp b/gpgsetownertrusteditinteractor.cpp
index 8df21d54..23a9f607 100644
--- a/gpgsetownertrusteditinteractor.cpp
+++ b/gpgsetownertrusteditinteractor.cpp
@@ -1,139 +1,141 @@
/*
gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "gpgsetownertrusteditinteractor.h"
#include "error.h"
#include <gpgme.h>
#include <cstring>
using std::strcmp;
// avoid conflict (msvc)
#ifdef ERROR
# undef ERROR
#endif
using namespace GpgME;
GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor( Key::OwnerTrust ot )
: EditInteractor(),
m_ownertrust( ot )
{
}
GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {}
// work around --enable-final
namespace GpgSetOwnerTrustEditInteractor_Private {
enum {
START = EditInteractor::StartState,
COMMAND,
VALUE,
REALLY_ULTIMATE,
QUIT,
SAVE,
ERROR = EditInteractor::ErrorState
};
}
-const char * GpgSetOwnerTrustEditInteractor::action() const {
+const char * GpgSetOwnerTrustEditInteractor::action( Error & err ) const {
static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" };
using namespace GpgSetOwnerTrustEditInteractor_Private;
switch ( state() ) {
case COMMAND:
return "trust";
case VALUE:
return truststrings[m_ownertrust];
case REALLY_ULTIMATE:
return "Y";
case QUIT:
return "quit";
case SAVE:
return "Y";
case START:
case ERROR:
return 0;
default:
- throw Error( gpg_error( GPG_ERR_GENERAL ) );
+ err = Error( gpg_error( GPG_ERR_GENERAL ) );
+ return 0;
}
}
-unsigned int GpgSetOwnerTrustEditInteractor::nextState( unsigned int status, const char * args ) const {
+unsigned int GpgSetOwnerTrustEditInteractor::nextState( unsigned int status, const char * args, Error & err ) const {
static const Error GENERAL_ERROR( gpg_error( GPG_ERR_GENERAL ) );
//static const Error INV_TIME_ERROR( gpg_error( GPG_ERR_INV_TIME ) );
if ( needsNoResponse( status ) )
return state();
using namespace GpgSetOwnerTrustEditInteractor_Private;
switch ( state() ) {
case START:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return COMMAND;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case COMMAND:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "edit_ownertrust.value" ) == 0 )
return VALUE;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case VALUE:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return QUIT;
else if ( status == GPGME_STATUS_GET_BOOL &&
strcmp( args, "edit_ownertrust.set_ultimate.okay" ) == 0 )
return REALLY_ULTIMATE;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case REALLY_ULTIMATE:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return QUIT;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case QUIT:
if ( status == GPGME_STATUS_GET_BOOL &&
strcmp( args, "keyedit.save.okay" ) == 0 )
return SAVE;
- else
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
case ERROR:
if ( status == GPGME_STATUS_GET_LINE &&
strcmp( args, "keyedit.prompt" ) == 0 )
return QUIT;
- else
- throw lastError();
+ err = lastError();
+ return ERROR;
default:
- throw GENERAL_ERROR;
+ err = GENERAL_ERROR;
+ return ERROR;
};
}
diff --git a/gpgsetownertrusteditinteractor.h b/gpgsetownertrusteditinteractor.h
index 5e1a5b3b..d8f51169 100644
--- a/gpgsetownertrusteditinteractor.h
+++ b/gpgsetownertrusteditinteractor.h
@@ -1,48 +1,48 @@
/*
gpgsetownertrusteditinteractor.h - Edit Interactor to change the owner trust of an OpenPGP key
Copyright (C) 2007 Klarälvdalens Datakonsult AB
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__
#define __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__
#include <gpgme++/editinteractor.h>
#include <gpgme++/key.h>
#include <string>
namespace GpgME {
class GPGMEPP_EXPORT GpgSetOwnerTrustEditInteractor : public EditInteractor {
public:
explicit GpgSetOwnerTrustEditInteractor( Key::OwnerTrust ownertrust );
~GpgSetOwnerTrustEditInteractor();
private:
- /* reimp */ const char * action() const;
- /* reimp */ unsigned int nextState( unsigned int statusCode, const char * args ) const;
+ /* reimp */ const char * action( Error & err ) const;
+ /* reimp */ unsigned int nextState( unsigned int statusCode, const char * args, Error & err ) const;
private:
const Key::OwnerTrust m_ownertrust;
};
} // namespace GpgME
#endif // __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 4, 2:26 PM (1 d, 5 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f5/22/e05aa5d0c490da54d7234f5a1725
Attached To
rGPGMEPP Gpgme plus plus
Event Timeline
Log In to Comment