|
Packit |
d7e8d0 |
/*
|
|
Packit |
d7e8d0 |
configuration.h - wraps gpgme configuration components
|
|
Packit |
d7e8d0 |
Copyright (C) 2010 Klarälvdalens Datakonsult AB
|
|
Packit |
d7e8d0 |
2016 Bundesamt für Sicherheit in der Informationstechnik
|
|
Packit |
d7e8d0 |
Software engineering by Intevation GmbH
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
This file is part of GPGME++.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGME++ is free software; you can redistribute it and/or
|
|
Packit |
d7e8d0 |
modify it under the terms of the GNU Library General Public
|
|
Packit |
d7e8d0 |
License as published by the Free Software Foundation; either
|
|
Packit |
d7e8d0 |
version 2 of the License, or (at your option) any later version.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGME++ is distributed in the hope that it will be useful,
|
|
Packit |
d7e8d0 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
d7e8d0 |
GNU Library General Public License for more details.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
You should have received a copy of the GNU Library General Public License
|
|
Packit |
d7e8d0 |
along with GPGME++; see the file COPYING.LIB. If not, write to the
|
|
Packit |
d7e8d0 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit |
d7e8d0 |
Boston, MA 02110-1301, USA.
|
|
Packit |
d7e8d0 |
*/
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
// -*- c++ -*-
|
|
Packit |
d7e8d0 |
#ifndef __GPGMEPP_CONFIGURATION_H__
|
|
Packit |
d7e8d0 |
#define __GPGMEPP_CONFIGURATION_H__
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "global.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "gpgmefw.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <iosfwd>
|
|
Packit |
d7e8d0 |
#include <vector>
|
|
Packit |
d7e8d0 |
#include <string>
|
|
Packit |
d7e8d0 |
#include <algorithm>
|
|
Packit |
d7e8d0 |
#include <memory>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
namespace GpgME
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
namespace Configuration
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
typedef std::shared_ptr< std::remove_pointer<gpgme_conf_comp_t>::type > shared_gpgme_conf_comp_t;
|
|
Packit |
d7e8d0 |
typedef std::weak_ptr< std::remove_pointer<gpgme_conf_comp_t>::type > weak_gpgme_conf_comp_t;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
class Argument;
|
|
Packit |
d7e8d0 |
class Option;
|
|
Packit |
d7e8d0 |
class Component;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
enum Level {
|
|
Packit |
d7e8d0 |
Basic,
|
|
Packit |
d7e8d0 |
Advanced,
|
|
Packit |
d7e8d0 |
Expert,
|
|
Packit |
d7e8d0 |
Invisible,
|
|
Packit |
d7e8d0 |
Internal,
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
NumLevels
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
enum Type {
|
|
Packit |
d7e8d0 |
NoType,
|
|
Packit |
d7e8d0 |
StringType,
|
|
Packit |
d7e8d0 |
IntegerType,
|
|
Packit |
d7e8d0 |
UnsignedIntegerType,
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
FilenameType = 32,
|
|
Packit |
d7e8d0 |
LdapServerType,
|
|
Packit |
d7e8d0 |
KeyFingerprintType,
|
|
Packit |
d7e8d0 |
PublicKeyType,
|
|
Packit |
d7e8d0 |
SecretKeyType,
|
|
Packit |
d7e8d0 |
AliasListType,
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
MaxType
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
enum Flag {
|
|
Packit |
d7e8d0 |
Group = (1 << 0),
|
|
Packit |
d7e8d0 |
Optional = (1 << 1),
|
|
Packit |
d7e8d0 |
List = (1 << 2),
|
|
Packit |
d7e8d0 |
Runtime = (1 << 3),
|
|
Packit |
d7e8d0 |
Default = (1 << 4),
|
|
Packit |
d7e8d0 |
DefaultDescription = (1 << 5),
|
|
Packit |
d7e8d0 |
NoArgumentDescription = (1 << 6),
|
|
Packit |
d7e8d0 |
NoChange = (1 << 7),
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
LastFlag = NoChange
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
// class Component
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
class GPGMEPP_EXPORT Component
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
public:
|
|
Packit |
d7e8d0 |
Component() : comp() {}
|
|
Packit |
d7e8d0 |
explicit Component(const shared_gpgme_conf_comp_t &gpgme_comp)
|
|
Packit |
d7e8d0 |
: comp(gpgme_comp) {}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
// copy ctor is ok
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const Component &operator=(const Component &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
if (this != &other) {
|
|
Packit |
d7e8d0 |
Component(other).swap(*this);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
return *this;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void swap(Component &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
using std::swap;
|
|
Packit |
d7e8d0 |
swap(this->comp, other.comp);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
bool isNull() const
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
return !comp;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
static std::vector<Component> load(Error &err;;
|
|
Packit |
d7e8d0 |
Error save() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const char *name() const;
|
|
Packit |
d7e8d0 |
const char *description() const;
|
|
Packit |
d7e8d0 |
const char *programName() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Option option(unsigned int index) const;
|
|
Packit |
d7e8d0 |
Option option(const char *name) const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
unsigned int numOptions() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
std::vector<Option> options() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull())
|
|
Packit |
d7e8d0 |
private:
|
|
Packit |
d7e8d0 |
shared_gpgme_conf_comp_t comp;
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
// class Option
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
class GPGMEPP_EXPORT Option
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
public:
|
|
Packit Service |
30b792 |
Option() : comp(), opt(nullptr) {}
|
|
Packit |
d7e8d0 |
Option(const shared_gpgme_conf_comp_t &gpgme_comp, gpgme_conf_opt_t gpgme_opt)
|
|
Packit |
d7e8d0 |
: comp(gpgme_comp), opt(gpgme_opt) {}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const Option &operator=(const Option &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
if (this != &other) {
|
|
Packit |
d7e8d0 |
Option(other).swap(*this);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
return *this;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void swap(Option &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
using std::swap;
|
|
Packit |
d7e8d0 |
swap(this->comp, other.comp);
|
|
Packit |
d7e8d0 |
swap(this->opt, other.opt);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
bool isNull() const
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
return comp.expired() || !opt;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Component parent() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
unsigned int flags() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Level level() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const char *name() const;
|
|
Packit |
d7e8d0 |
const char *description() const;
|
|
Packit |
d7e8d0 |
const char *argumentName() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Type type() const;
|
|
Packit |
d7e8d0 |
Type alternateType() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Argument defaultValue() const;
|
|
Packit |
d7e8d0 |
const char *defaultDescription() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Argument noArgumentValue() const;
|
|
Packit |
d7e8d0 |
const char *noArgumentDescription() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
/*! The value that is in the config file (or null, if it's not set). */
|
|
Packit |
d7e8d0 |
Argument activeValue() const;
|
|
Packit |
d7e8d0 |
/*! The value that is in this object, ie. either activeValue(), newValue(), or defaultValue() */
|
|
Packit |
d7e8d0 |
Argument currentValue() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Argument newValue() const;
|
|
Packit |
d7e8d0 |
bool set() const;
|
|
Packit |
d7e8d0 |
bool dirty() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Error setNewValue(const Argument &argument);
|
|
Packit |
d7e8d0 |
Error resetToDefaultValue();
|
|
Packit |
d7e8d0 |
Error resetToActiveValue();
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Argument createNoneArgument(bool set) const;
|
|
Packit |
d7e8d0 |
Argument createStringArgument(const char *value) const;
|
|
Packit |
d7e8d0 |
Argument createStringArgument(const std::string &value) const;
|
|
Packit |
d7e8d0 |
Argument createIntArgument(int value) const;
|
|
Packit |
d7e8d0 |
Argument createUIntArgument(unsigned int value) const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Argument createNoneListArgument(unsigned int count) const;
|
|
Packit |
d7e8d0 |
Argument createStringListArgument(const std::vector<const char *> &value) const;
|
|
Packit |
d7e8d0 |
Argument createStringListArgument(const std::vector<std::string> &value) const;
|
|
Packit |
d7e8d0 |
Argument createIntListArgument(const std::vector<int> &values) const;
|
|
Packit |
d7e8d0 |
Argument createUIntListArgument(const std::vector<unsigned int> &values) const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull())
|
|
Packit |
d7e8d0 |
private:
|
|
Packit |
d7e8d0 |
weak_gpgme_conf_comp_t comp;
|
|
Packit |
d7e8d0 |
gpgme_conf_opt_t opt;
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
// class Argument
|
|
Packit |
d7e8d0 |
//
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
class GPGMEPP_EXPORT Argument
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
friend class ::GpgME::Configuration::Option;
|
|
Packit |
d7e8d0 |
Argument(const shared_gpgme_conf_comp_t &comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg, bool owns);
|
|
Packit |
d7e8d0 |
public:
|
|
Packit Service |
30b792 |
Argument() : comp(), opt(nullptr), arg(nullptr) {}
|
|
Packit |
d7e8d0 |
//Argument( const shared_gpgme_conf_comp_t & comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg );
|
|
Packit |
d7e8d0 |
Argument(const Argument &other);
|
|
Packit |
d7e8d0 |
~Argument();
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const Argument &operator=(const Argument &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
if (this != &other) {
|
|
Packit |
d7e8d0 |
Argument(other).swap(*this);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
return *this;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void swap(Argument &other)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
using std::swap;
|
|
Packit |
d7e8d0 |
swap(this->comp, other.comp);
|
|
Packit |
d7e8d0 |
swap(this->opt, other.opt);
|
|
Packit |
d7e8d0 |
swap(this->arg, other.arg);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
bool isNull() const
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
return comp.expired() || !opt || !arg;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Option parent() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
unsigned int numElements() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
bool boolValue() const;
|
|
Packit |
d7e8d0 |
const char *stringValue(unsigned int index = 0) const;
|
|
Packit |
d7e8d0 |
int intValue(unsigned int index = 0) const;
|
|
Packit |
d7e8d0 |
unsigned int uintValue(unsigned int index = 0) const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
unsigned int numberOfTimesSet() const;
|
|
Packit |
d7e8d0 |
std::vector<const char *> stringValues() const;
|
|
Packit |
d7e8d0 |
std::vector<int> intValues() const;
|
|
Packit |
d7e8d0 |
std::vector<unsigned int> uintValues() const;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull())
|
|
Packit |
d7e8d0 |
private:
|
|
Packit |
d7e8d0 |
weak_gpgme_conf_comp_t comp;
|
|
Packit |
d7e8d0 |
gpgme_conf_opt_t opt;
|
|
Packit |
d7e8d0 |
gpgme_conf_arg_t arg;
|
|
Packit |
d7e8d0 |
};
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Level level);
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Type type);
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Flag flag);
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Component &component);
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Option &option);
|
|
Packit |
d7e8d0 |
GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Argument &argument);
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
} // namespace Configuration
|
|
Packit |
d7e8d0 |
} // namespace GpgME
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Component)
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Option)
|
|
Packit |
d7e8d0 |
GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Argument)
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#endif // __GPGMEPP_CONFIGURATION_H__
|