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

Generated by: LCOV version 1.11