cpp: Handle statuses that need no response in the base edit interactor

* lang/cpp/src/editinteractor.cpp (edit_interactor_callback_impl): Do
not call nextState() if status needs no response.
* lang/cpp/src/gpgaddexistingsubkeyeditinteractor.cpp
(GpgAddExistingSubkeyEditInteractor::Private::nextState),
lang/cpp/src/gpgadduserideditinteractor.cpp
(GpgAddUserIDEditInteractor::nextState),
lang/cpp/src/gpggencardkeyinteractor.cpp
(GpgGenCardKeyInteractor::nextState),
lang/cpp/src/gpgrevokekeyeditinteractor.cpp
(GpgRevokeKeyEditInteractor::Private::nextState),
lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp
(GpgSetExpiryTimeEditInteractor::nextState),
lang/cpp/src/gpgsetownertrusteditinteractor.cpp
(GpgSetOwnerTrustEditInteractor::nextState),
lang/cpp/src/gpgsignkeyeditinteractor.cpp
(GpgSignKeyEditInteractor::nextState): Remove handling of statuses that
need no response.
--

This change removes superfluous code duplication.

GnuPG-bug-id: 6305
This commit is contained in:
Ingo Klöcker 2022-12-08 15:20:14 +01:00
parent d04d7b174f
commit c419376b85
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
8 changed files with 7 additions and 28 deletions

View File

@ -96,7 +96,13 @@ public:
// advance to next state based on input: // advance to next state based on input:
const unsigned int oldState = ei->state; const unsigned int oldState = ei->state;
ei->state = ei->q->nextState(status, args, err);
if (ei->q->needsNoResponse(status)) {
// keep state
} else {
ei->state = ei->q->nextState(status, args, err);
}
if (ei->debug) { if (ei->debug) {
std::fprintf(ei->debug, "EditInteractor: %u -> nextState( %s, %s ) -> %u\n", std::fprintf(ei->debug, "EditInteractor: %u -> nextState( %s, %s ) -> %u\n",
oldState, status_to_string(status), args ? args : "<null>", ei->state); oldState, status_to_string(status), args ? args : "<null>", ei->state);

View File

@ -105,10 +105,6 @@ unsigned int GpgAddExistingSubkeyEditInteractor::Private::nextState(unsigned int
static const Error NO_KEY_ERROR = Error::fromCode(GPG_ERR_NO_KEY); static const Error NO_KEY_ERROR = Error::fromCode(GPG_ERR_NO_KEY);
static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME); static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME);
if (q->needsNoResponse(status)) {
return q->state();
}
switch (q->state()) { switch (q->state()) {
case START: case START:
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&

View File

@ -120,10 +120,6 @@ unsigned int GpgAddUserIDEditInteractor::nextState(unsigned int status, const ch
static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
if (needsNoResponse(status)) {
return state();
}
using namespace GpgAddUserIDEditInteractor_Private; using namespace GpgAddUserIDEditInteractor_Private;
switch (state()) { switch (state()) {

View File

@ -192,10 +192,6 @@ unsigned int GpgGenCardKeyInteractor::nextState(unsigned int status, const char
static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
if (needsNoResponse(status)) {
return state();
}
using namespace GpgGenCardKeyInteractor_Private; using namespace GpgGenCardKeyInteractor_Private;
switch (state()) { switch (state()) {

View File

@ -112,10 +112,6 @@ unsigned int GpgRevokeKeyEditInteractor::Private::nextState(unsigned int status,
static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
if (q->needsNoResponse(status)) {
return q->state();
}
if (status == GPGME_STATUS_ERROR) { if (status == GPGME_STATUS_ERROR) {
err = q->parseStatusError(args); err = q->parseStatusError(args);
return ERROR; return ERROR;

View File

@ -94,10 +94,6 @@ unsigned int GpgSetExpiryTimeEditInteractor::nextState(unsigned int status, cons
static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME); static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME);
if (needsNoResponse(status)) {
return state();
}
using namespace GpgSetExpiryTimeEditInteractor_Private; using namespace GpgSetExpiryTimeEditInteractor_Private;
switch (state()) { switch (state()) {

View File

@ -98,10 +98,6 @@ unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, cons
static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
//static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME ); //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
if (needsNoResponse(status)) {
return state();
}
using namespace GpgSetOwnerTrustEditInteractor_Private; using namespace GpgSetOwnerTrustEditInteractor_Private;
switch (state()) { switch (state()) {

View File

@ -304,9 +304,6 @@ unsigned int GpgSignKeyEditInteractor::nextState(unsigned int status, const char
static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
//static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME ); //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
static const TransitionMap table(makeTable()); static const TransitionMap table(makeTable());
if (needsNoResponse(status)) {
return state();
}
using namespace GpgSignKeyEditInteractor_Private; using namespace GpgSignKeyEditInteractor_Private;