LCOV - code coverage report
Current view: top level - lang/cpp/src - gpgsetexpirytimeeditinteractor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 50 0.0 %
Date: 2016-09-12 13:07:23 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :   gpgsetexpirytimeeditinteractor.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 "gpgsetexpirytimeeditinteractor.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           0 : GpgSetExpiryTimeEditInteractor::GpgSetExpiryTimeEditInteractor(const std::string &t)
      40             :     : EditInteractor(),
      41           0 :       m_strtime(t)
      42             : {
      43             : 
      44           0 : }
      45             : 
      46           0 : GpgSetExpiryTimeEditInteractor::~GpgSetExpiryTimeEditInteractor() {}
      47             : 
      48             : // work around --enable-final
      49             : namespace GpgSetExpiryTimeEditInteractor_Private
      50             : {
      51             : enum {
      52             :     START = EditInteractor::StartState,
      53             :     COMMAND,
      54             :     DATE,
      55             :     QUIT,
      56             :     SAVE,
      57             : 
      58             :     ERROR = EditInteractor::ErrorState
      59             : };
      60             : }
      61             : 
      62           0 : const char *GpgSetExpiryTimeEditInteractor::action(Error &err) const
      63             : {
      64             : 
      65             :     using namespace GpgSetExpiryTimeEditInteractor_Private;
      66             : 
      67           0 :     switch (state()) {
      68             :     case COMMAND:
      69           0 :         return "expire";
      70             :     case DATE:
      71           0 :         return m_strtime.c_str();
      72             :     case QUIT:
      73           0 :         return "quit";
      74             :     case SAVE:
      75           0 :         return "Y";
      76             :     case START:
      77             :     case ERROR:
      78           0 :         return 0;
      79             :     default:
      80           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
      81           0 :         return 0;
      82             :     }
      83             : }
      84             : 
      85           0 : unsigned int GpgSetExpiryTimeEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
      86             : {
      87             : 
      88           0 :     static const Error GENERAL_ERROR  = Error::fromCode(GPG_ERR_GENERAL);
      89           0 :     static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME);
      90             : 
      91           0 :     if (needsNoResponse(status)) {
      92           0 :         return state();
      93             :     }
      94             : 
      95             :     using namespace GpgSetExpiryTimeEditInteractor_Private;
      96             : 
      97           0 :     switch (state()) {
      98             :     case START:
      99           0 :         if (status == GPGME_STATUS_GET_LINE &&
     100           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     101           0 :             return COMMAND;
     102             :         }
     103           0 :         err = GENERAL_ERROR;
     104           0 :         return ERROR;
     105             :     case COMMAND:
     106           0 :         if (status == GPGME_STATUS_GET_LINE &&
     107           0 :                 strcmp(args, "keygen.valid") == 0) {
     108           0 :             return DATE;
     109             :         }
     110           0 :         err = GENERAL_ERROR;
     111           0 :         return ERROR;
     112             :     case DATE:
     113           0 :         if (status == GPGME_STATUS_GET_LINE &&
     114           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     115           0 :             return QUIT;
     116           0 :         } else if (status == GPGME_STATUS_GET_LINE &&
     117           0 :                    strcmp(args, "keygen.valid")) {
     118           0 :             err = INV_TIME_ERROR;
     119           0 :             return ERROR;
     120             :         }
     121           0 :         err = GENERAL_ERROR;
     122           0 :         return ERROR;
     123             :     case QUIT:
     124           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     125           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     126           0 :             return SAVE;
     127             :         }
     128           0 :         err = GENERAL_ERROR;
     129           0 :         return ERROR;
     130             :     case ERROR:
     131           0 :         if (status == GPGME_STATUS_GET_LINE &&
     132           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     133           0 :             return QUIT;
     134             :         }
     135           0 :         err = lastError();
     136           0 :         return ERROR;
     137             :     default:
     138           0 :         err = GENERAL_ERROR;
     139           0 :         return ERROR;
     140             :     }
     141             : }

Generated by: LCOV version 1.11