LCOV - code coverage report
Current view: top level - lang/cpp/src - gpgsetownertrusteditinteractor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 54 55.6 %
Date: 2016-09-12 13:07:23 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :   gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
       3             :   Copyright (C) 2007 Klarälvdalens Datakonsult AB
       4             : 
       5             :   This file is part of GPGME++.
       6             : 
       7             :   GPGME++ is free software; you can redistribute it and/or
       8             :   modify it under the terms of the GNU Library General Public
       9             :   License as published by the Free Software Foundation; either
      10             :   version 2 of the License, or (at your option) any later version.
      11             : 
      12             :   GPGME++ is distributed in the hope that it will be useful,
      13             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :   GNU Library General Public License for more details.
      16             : 
      17             :   You should have received a copy of the GNU Library General Public License
      18             :   along with GPGME++; see the file COPYING.LIB.  If not, write to the
      19             :   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      20             :   Boston, MA 02110-1301, USA.
      21             : */
      22             : 
      23             : #include "gpgsetownertrusteditinteractor.h"
      24             : #include "error.h"
      25             : 
      26             : #include <gpgme.h>
      27             : 
      28             : #include <cstring>
      29             : 
      30             : using std::strcmp;
      31             : 
      32             : // avoid conflict (msvc)
      33             : #ifdef ERROR
      34             : # undef ERROR
      35             : #endif
      36             : 
      37             : using namespace GpgME;
      38             : 
      39           2 : GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot)
      40             :     : EditInteractor(),
      41           2 :       m_ownertrust(ot)
      42             : {
      43             : 
      44           2 : }
      45             : 
      46           4 : GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {}
      47             : 
      48             : // work around --enable-final
      49             : namespace GpgSetOwnerTrustEditInteractor_Private
      50             : {
      51             : enum {
      52             :     START = EditInteractor::StartState,
      53             :     COMMAND,
      54             :     VALUE,
      55             :     REALLY_ULTIMATE,
      56             :     QUIT,
      57             :     SAVE,
      58             : 
      59             :     ERROR = EditInteractor::ErrorState
      60             : };
      61             : }
      62             : 
      63           7 : const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const
      64             : {
      65             :     static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" };
      66             : 
      67             :     using namespace GpgSetOwnerTrustEditInteractor_Private;
      68             : 
      69           7 :     switch (state()) {
      70             :     case COMMAND:
      71           2 :         return "trust";
      72             :     case VALUE:
      73           2 :         return truststrings[m_ownertrust];
      74             :     case REALLY_ULTIMATE:
      75           1 :         return "Y";
      76             :     case QUIT:
      77           2 :         return "quit";
      78             :     case SAVE:
      79           0 :         return "Y";
      80             :     case START:
      81             :     case ERROR:
      82           0 :         return 0;
      83             :     default:
      84           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
      85           0 :         return 0;
      86             :     }
      87             : }
      88             : 
      89          28 : unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
      90             : {
      91             : 
      92          28 :     static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
      93             :     //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
      94             : 
      95          28 :     if (needsNoResponse(status)) {
      96          21 :         return state();
      97             :     }
      98             : 
      99             :     using namespace GpgSetOwnerTrustEditInteractor_Private;
     100             : 
     101           7 :     switch (state()) {
     102             :     case START:
     103           4 :         if (status == GPGME_STATUS_GET_LINE &&
     104           2 :                 strcmp(args, "keyedit.prompt") == 0) {
     105           2 :             return COMMAND;
     106             :         }
     107           0 :         err = GENERAL_ERROR;
     108           0 :         return ERROR;
     109             :     case COMMAND:
     110           4 :         if (status == GPGME_STATUS_GET_LINE &&
     111           2 :                 strcmp(args, "edit_ownertrust.value") == 0) {
     112           2 :             return VALUE;
     113             :         }
     114           0 :         err = GENERAL_ERROR;
     115           0 :         return ERROR;
     116             :     case VALUE:
     117           3 :         if (status == GPGME_STATUS_GET_LINE &&
     118           1 :                 strcmp(args, "keyedit.prompt") == 0) {
     119           1 :             return QUIT;
     120           2 :         } else if (status == GPGME_STATUS_GET_BOOL &&
     121           1 :                    strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) {
     122           1 :             return REALLY_ULTIMATE;
     123             :         }
     124           0 :         err = GENERAL_ERROR;
     125           0 :         return ERROR;
     126             :     case REALLY_ULTIMATE:
     127           2 :         if (status == GPGME_STATUS_GET_LINE &&
     128           1 :                 strcmp(args, "keyedit.prompt") == 0) {
     129           1 :             return QUIT;
     130             :         }
     131           0 :         err = GENERAL_ERROR;
     132           0 :         return ERROR;
     133             :     case QUIT:
     134           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     135           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     136           0 :             return SAVE;
     137             :         }
     138           0 :         err = GENERAL_ERROR;
     139           0 :         return ERROR;
     140             :     case ERROR:
     141           0 :         if (status == GPGME_STATUS_GET_LINE &&
     142           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     143           0 :             return QUIT;
     144             :         }
     145           0 :         err = lastError();
     146           0 :         return ERROR;
     147             :     default:
     148           0 :         err = GENERAL_ERROR;
     149           0 :         return ERROR;
     150             :     };
     151             : }

Generated by: LCOV version 1.11