// Copyright (c) 2011-2016 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "PaymentServiceConfiguration.h" #include #include #include #include "Logging/ILogger.h" namespace po = boost::program_options; namespace PaymentService { Configuration::Configuration() { generateNewContainer = false; daemonize = false; registerService = false; unregisterService = false; logFile = "payment_gate.log"; testnet = false; printAddresses = false; logLevel = Logging::INFO; bindAddress = ""; bindPort = 0; } void Configuration::initOptions(boost::program_options::options_description& desc) { desc.add_options() ("bind-address", po::value()->default_value("0.0.0.0"), "payment service bind address") ("bind-port", po::value()->default_value(8070), "payment service bind port") ("container-file,w", po::value(), "container file") ("container-password,p", po::value(), "container password") ("generate-container,g", "generate new container file with one wallet and exit") ("daemon,d", "run as daemon in Unix or as service in Windows") #ifdef _WIN32 ("register-service", "register service and exit (Windows only)") ("unregister-service", "unregister service and exit (Windows only)") #endif ("log-file,l", po::value(), "log file") ("server-root", po::value(), "server root. The service will use it as working directory. Don't set it if don't want to change it") ("log-level", po::value(), "log level") ("address", "print wallet addresses and exit"); } void Configuration::init(const boost::program_options::variables_map& options) { if (options.count("daemon") != 0) { daemonize = true; } if (options.count("register-service") != 0) { registerService = true; } if (options.count("unregister-service") != 0) { unregisterService = true; } if (registerService && unregisterService) { throw ConfigurationError("It's impossible to use both \"register-service\" and \"unregister-service\" at the same time"); } if (options["testnet"].as()) { testnet = true; } if (options.count("log-file") != 0) { logFile = options["log-file"].as(); } if (options.count("log-level") != 0) { logLevel = options["log-level"].as(); if (logLevel > Logging::TRACE) { std::string error = "log-level option must be in " + std::to_string(Logging::FATAL) + ".." + std::to_string(Logging::TRACE) + " interval"; throw ConfigurationError(error.c_str()); } } if (options.count("server-root") != 0) { serverRoot = options["server-root"].as(); } if (options.count("bind-address") != 0 && (!options["bind-address"].defaulted() || bindAddress.empty())) { bindAddress = options["bind-address"].as(); } if (options.count("bind-port") != 0 && (!options["bind-port"].defaulted() || bindPort == 0)) { bindPort = options["bind-port"].as(); } if (options.count("container-file") != 0) { containerFile = options["container-file"].as(); } if (options.count("container-password") != 0) { containerPassword = options["container-password"].as(); } if (options.count("generate-container") != 0) { generateNewContainer = true; } if (options.count("address") != 0) { printAddresses = true; } if (!registerService && !unregisterService) { if (containerFile.empty() || containerPassword.empty()) { throw ConfigurationError("Both container-file and container-password parameters are required"); } } } } //namespace PaymentService