// OpenVPN -- An application to securely tunnel IP networks // over a single port, with support for SSL/TLS-based // session authentication and key exchange, // packet encryption, packet authentication, and // packet compression. // // Copyright (C) 2012-2017 OpenVPN Inc. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License Version 3 // as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program in the COPYING file. // If not, see . // General-purpose options parser, used to parse the OpenVPN configuration // file as well as the server-pushed options list. Note that these classes // don't get into the interpretation or typing of options -- they only care // about parsing the options into lists of strings, and then presenting the // complete configuration file as a list of options. // // The parser understands the general grammar of OpenVPN configuration // files including: // // 1. option/argument parsing, quoting, escaping, and comments, // 2. inline directives such as // // ... // // 3. and meta-directives such as those used by OpenVPN Access Server such as: // # OVPN_ACCESS_SERVER_USERNAME=test // // The basic organization of the parser is as follows: // // Option -- a list of strings, where the first string is the // option/directive name, and subsequent strings are arguments. // // OptionList -- a list of Options that also contains a map for // optimal lookup of specific options #ifndef OPENVPN_COMMON_OPTIONS_H #define OPENVPN_COMMON_OPTIONS_H #include #include #include #include // for std::sort, std::min #include // for std::move #include // for std::is_nothrow_move_constructible #include #include // for std::uint64_t #include #include #include #include #include #include #include #include #include namespace openvpn { class Option { public: enum { MULTILINE = 0x8000000, }; // Validate string by size and multiline status. // OR max_len with MULTILINE to allow multiline string. // Return values: enum validate_status { STATUS_GOOD, STATUS_MULTILINE, STATUS_LENGTH, }; // Options for render methods enum render_flags { RENDER_TRUNC_64 = (1<<0), // truncate option after 64 chars RENDER_PASS_FMT = (1<<1), // pass \r\n\t RENDER_NUMBER = (1<<2), // number lines RENDER_BRACKET = (1<<3), // quote options using [] RENDER_UNUSED = (1<<4), // only show unused options }; Option() { static_assert(std::is_nothrow_move_constructible