LCOV - code coverage report
Current view: top level - lang/cpp/src - gpgadduserideditinteractor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 78 0.0 %
Date: 2016-12-01 18:45:36 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /*
       2             :   gpgadduserideditinteractor.cpp - Edit Interactor to add a new UID to an OpenPGP key
       3             :   Copyright (C) 2008 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 "gpgadduserideditinteractor.h"
      28             : 
      29             : #include "error.h"
      30             : 
      31             : #include <gpgme.h>
      32             : 
      33             : #include <cstring>
      34             : 
      35             : using std::strcmp;
      36             : 
      37             : // avoid conflict (msvc)
      38             : #ifdef ERROR
      39             : # undef ERROR
      40             : #endif
      41             : 
      42             : using namespace GpgME;
      43             : 
      44           0 : GpgAddUserIDEditInteractor::GpgAddUserIDEditInteractor()
      45             :     : EditInteractor(),
      46             :       m_name(),
      47             :       m_email(),
      48           0 :       m_comment()
      49             : {
      50             : 
      51           0 : }
      52             : 
      53           0 : GpgAddUserIDEditInteractor::~GpgAddUserIDEditInteractor() {}
      54             : 
      55           0 : void GpgAddUserIDEditInteractor::setNameUtf8(const std::string &name)
      56             : {
      57           0 :     m_name = name;
      58           0 : }
      59             : 
      60           0 : void GpgAddUserIDEditInteractor::setEmailUtf8(const std::string &email)
      61             : {
      62           0 :     m_email = email;
      63           0 : }
      64             : 
      65           0 : void GpgAddUserIDEditInteractor::setCommentUtf8(const std::string &comment)
      66             : {
      67           0 :     m_comment = comment;
      68           0 : }
      69             : 
      70             : // work around --enable-final
      71             : namespace GpgAddUserIDEditInteractor_Private
      72             : {
      73             : enum {
      74             :     START = EditInteractor::StartState,
      75             :     COMMAND,
      76             :     NAME,
      77             :     EMAIL,
      78             :     COMMENT,
      79             :     QUIT,
      80             :     SAVE,
      81             : 
      82             :     ERROR = EditInteractor::ErrorState
      83             : };
      84             : }
      85             : 
      86           0 : const char *GpgAddUserIDEditInteractor::action(Error &err) const
      87             : {
      88             : 
      89             :     using namespace GpgAddUserIDEditInteractor_Private;
      90             : 
      91           0 :     switch (state()) {
      92             :     case COMMAND:
      93           0 :         return "adduid";
      94             :     case NAME:
      95           0 :         return m_name.c_str();
      96             :     case EMAIL:
      97           0 :         return m_email.c_str();
      98             :     case COMMENT:
      99           0 :         return m_comment.c_str();
     100             :     case QUIT:
     101           0 :         return "quit";
     102             :     case SAVE:
     103           0 :         return "Y";
     104             :     case START:
     105             :     case ERROR:
     106           0 :         return 0;
     107             :     default:
     108           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
     109           0 :         return 0;
     110             :     }
     111             : }
     112             : 
     113           0 : unsigned int GpgAddUserIDEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
     114             : {
     115             : 
     116           0 :     static const Error GENERAL_ERROR     = Error::fromCode(GPG_ERR_GENERAL);
     117           0 :     static const Error INV_NAME_ERROR    = Error::fromCode(GPG_ERR_INV_NAME);
     118           0 :     static const Error INV_EMAIL_ERROR   = Error::fromCode(GPG_ERR_INV_USER_ID);
     119           0 :     static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
     120             : 
     121           0 :     if (needsNoResponse(status)) {
     122           0 :         return state();
     123             :     }
     124             : 
     125             :     using namespace GpgAddUserIDEditInteractor_Private;
     126             : 
     127           0 :     switch (state()) {
     128             :     case START:
     129           0 :         if (status == GPGME_STATUS_GET_LINE &&
     130           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     131           0 :             return COMMAND;
     132             :         }
     133           0 :         err = GENERAL_ERROR;
     134           0 :         return ERROR;
     135             :     case COMMAND:
     136           0 :         if (status == GPGME_STATUS_GET_LINE &&
     137           0 :                 strcmp(args, "keygen.name") == 0) {
     138           0 :             return NAME;
     139             :         }
     140           0 :         err = GENERAL_ERROR;
     141           0 :         return ERROR;
     142             :     case NAME:
     143           0 :         if (status == GPGME_STATUS_GET_LINE &&
     144           0 :                 strcmp(args, "keygen.email") == 0) {
     145           0 :             return EMAIL;
     146             :         }
     147           0 :         err = GENERAL_ERROR;
     148           0 :         if (status == GPGME_STATUS_GET_LINE &&
     149           0 :                 strcmp(args, "keygen.name") == 0) {
     150           0 :             err = INV_NAME_ERROR;
     151             :         }
     152           0 :         return ERROR;
     153             :     case EMAIL:
     154           0 :         if (status == GPGME_STATUS_GET_LINE &&
     155           0 :                 strcmp(args, "keygen.comment") == 0) {
     156           0 :             return COMMENT;
     157             :         }
     158           0 :         err = GENERAL_ERROR;
     159           0 :         if (status == GPGME_STATUS_GET_LINE &&
     160           0 :                 strcmp(args, "keygen.email") == 0) {
     161           0 :             err = INV_EMAIL_ERROR;
     162             :         }
     163           0 :         return ERROR;
     164             :     case COMMENT:
     165           0 :         if (status == GPGME_STATUS_GET_LINE &&
     166           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     167           0 :             return QUIT;
     168             :         }
     169           0 :         err = GENERAL_ERROR;
     170           0 :         if (status == GPGME_STATUS_GET_LINE &&
     171           0 :                 strcmp(args, "keygen.comment") == 0) {
     172           0 :             err = INV_COMMENT_ERROR;
     173             :         }
     174           0 :         return ERROR;
     175             :     case QUIT:
     176           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     177           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     178           0 :             return SAVE;
     179             :         }
     180           0 :         err = GENERAL_ERROR;
     181           0 :         return ERROR;
     182             :     case ERROR:
     183           0 :         if (status == GPGME_STATUS_GET_LINE &&
     184           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     185           0 :             return QUIT;
     186             :         }
     187           0 :         err = lastError();
     188           0 :         return ERROR;
     189             :     default:
     190           0 :         err = GENERAL_ERROR;
     191           0 :         return ERROR;
     192             :     }
     193             : }

Generated by: LCOV version 1.11