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-11-29 15:07:43 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             : #ifdef HAVE_CONFIG_H
      24             :  #include "config.h"
      25             : #endif
      26             : 
      27             : #include "gpgsetownertrusteditinteractor.h"
      28             : #include "error.h"
      29             : 
      30             : #include <gpgme.h>
      31             : 
      32             : #include <cstring>
      33             : 
      34             : using std::strcmp;
      35             : 
      36             : // avoid conflict (msvc)
      37             : #ifdef ERROR
      38             : # undef ERROR
      39             : #endif
      40             : 
      41             : using namespace GpgME;
      42             : 
      43           2 : GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot)
      44             :     : EditInteractor(),
      45           2 :       m_ownertrust(ot)
      46             : {
      47             : 
      48           2 : }
      49             : 
      50           4 : GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {}
      51             : 
      52             : // work around --enable-final
      53             : namespace GpgSetOwnerTrustEditInteractor_Private
      54             : {
      55             : enum {
      56             :     START = EditInteractor::StartState,
      57             :     COMMAND,
      58             :     VALUE,
      59             :     REALLY_ULTIMATE,
      60             :     QUIT,
      61             :     SAVE,
      62             : 
      63             :     ERROR = EditInteractor::ErrorState
      64             : };
      65             : }
      66             : 
      67           7 : const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const
      68             : {
      69             :     static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" };
      70             : 
      71             :     using namespace GpgSetOwnerTrustEditInteractor_Private;
      72             : 
      73           7 :     switch (state()) {
      74             :     case COMMAND:
      75           2 :         return "trust";
      76             :     case VALUE:
      77           2 :         return truststrings[m_ownertrust];
      78             :     case REALLY_ULTIMATE:
      79           1 :         return "Y";
      80             :     case QUIT:
      81           2 :         return "quit";
      82             :     case SAVE:
      83           0 :         return "Y";
      84             :     case START:
      85             :     case ERROR:
      86           0 :         return 0;
      87             :     default:
      88           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
      89           0 :         return 0;
      90             :     }
      91             : }
      92             : 
      93          28 : unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
      94             : {
      95             : 
      96          28 :     static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
      97             :     //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
      98             : 
      99          28 :     if (needsNoResponse(status)) {
     100          21 :         return state();
     101             :     }
     102             : 
     103             :     using namespace GpgSetOwnerTrustEditInteractor_Private;
     104             : 
     105           7 :     switch (state()) {
     106             :     case START:
     107           4 :         if (status == GPGME_STATUS_GET_LINE &&
     108           2 :                 strcmp(args, "keyedit.prompt") == 0) {
     109           2 :             return COMMAND;
     110             :         }
     111           0 :         err = GENERAL_ERROR;
     112           0 :         return ERROR;
     113             :     case COMMAND:
     114           4 :         if (status == GPGME_STATUS_GET_LINE &&
     115           2 :                 strcmp(args, "edit_ownertrust.value") == 0) {
     116           2 :             return VALUE;
     117             :         }
     118           0 :         err = GENERAL_ERROR;
     119           0 :         return ERROR;
     120             :     case VALUE:
     121           3 :         if (status == GPGME_STATUS_GET_LINE &&
     122           1 :                 strcmp(args, "keyedit.prompt") == 0) {
     123           1 :             return QUIT;
     124           2 :         } else if (status == GPGME_STATUS_GET_BOOL &&
     125           1 :                    strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) {
     126           1 :             return REALLY_ULTIMATE;
     127             :         }
     128           0 :         err = GENERAL_ERROR;
     129           0 :         return ERROR;
     130             :     case REALLY_ULTIMATE:
     131           2 :         if (status == GPGME_STATUS_GET_LINE &&
     132           1 :                 strcmp(args, "keyedit.prompt") == 0) {
     133           1 :             return QUIT;
     134             :         }
     135           0 :         err = GENERAL_ERROR;
     136           0 :         return ERROR;
     137             :     case QUIT:
     138           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     139           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     140           0 :             return SAVE;
     141             :         }
     142           0 :         err = GENERAL_ERROR;
     143           0 :         return ERROR;
     144             :     case ERROR:
     145           0 :         if (status == GPGME_STATUS_GET_LINE &&
     146           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     147           0 :             return QUIT;
     148             :         }
     149           0 :         err = lastError();
     150           0 :         return ERROR;
     151             :     default:
     152           0 :         err = GENERAL_ERROR;
     153           0 :         return ERROR;
     154             :     };
     155             : }

Generated by: LCOV version 1.11