Since version 6.0.0, tinyxml2 has introduced an API change
which broke compatibility with previous versions, see
https://github.com/leethomason/tinyxml2/issues/635
The library doesn't provide macros to check its version
in compile time, so we use pkg-config to determine library
version and define our own macro which we use for compatibility
with old (Ubuntu 16) and new (Ubuntu 18) library versions.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
If HTTPCLI_RANDOMIZE_RESULTS_REQUIRED is defined, cause a compile-time
error if Asio is not compiled with results.randomize() method.
If HTTPCLI_RANDOMIZE_RESULTS_REQUIRED is NOT defined, opportunistically
compile results.randomize() usage only if available in Asio.
Signed-off-by: James Yonan <james@openvpn.net>
std::strerror() doesn't claim to be thread-safe, so
add openvpn::strerror_str() which is thread-safe by
virtue of the fact that it backs to strerror_r().
Signed-off-by: James Yonan <james@openvpn.net>
Also, break out json::fmt_name* methods into their own
source file.
NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.
Signed-off-by: James Yonan <james@openvpn.net>
BijectiveSetMapping is a one-to-many bijective mapping.
If K is the key and V is the value, you can:
1. add to the forward map in the form [ K : set(V) ]
2. delete K from the forward map
The BijectiveSetMapping automatically maintains the
reverse mapping where each element is the form:
[ V: set(K) ]
Also enhanced StringTempl::to_string() with an SFINAE
variant that supports objects having a to_string() method.
Signed-off-by: James Yonan <james@openvpn.net>
Also, break out json::fmt_name* methods into their own
source file.
NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.
Signed-off-by: James Yonan <james@openvpn.net>
Also, break out json::fmt_name* methods into their own
source file.
NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.
Signed-off-by: James Yonan <james@openvpn.net>
* Added simple parse() method that only requires
JSON string to be parsed.
* Added get_string_from_array() method that doesn't
require title parameter.
* Added cast_array() method that doesn't require
title parameter.
Signed-off-by: James Yonan <james@openvpn.net>
Also:
* break up some long lines in source code
* added get_uint_optional_via_string() and
get_uint64_optional_via_string()
Signed-off-by: James Yonan <james@openvpn.net>
* use namespace json instead of class json so that other
source files can also add stuff to namespace json
* make fmt_name() method public
* added get_string_from_array() method
* added get_(int|uint|uint64)_optional() methods
* added get_(uint|uint64)_via_string() methods
* added some title-free method variants such as get_dict()
and cast_dict()
Signed-off-by: James Yonan <james@openvpn.net>
* Templatize name and title parameters.
* String construct the json_parse exceptions instead of
using OPENVPN_THROW.
* Refactor to_x() methods to derive from get_x() methods
instead of the other way around.
* Added get_uint64() method.
* Added cast_array() method.
* Added format() method.
This fixes build on Android NDK with clang/clang++
Neither the Android libc nor the libc++ used by Android by default
have the __bswap_constant_64 macro.
The more standard include of byteswap.h and bswap_64 exists only on
Linux and Android. Mac OS X defines no function in its includes that
does a byteswap. Therefore keep the compiler internal but choose
Clang's when compiling with Clang.
1. Don't emit spaces if the input string is empty.
2. Don't emit spaces after the last newline in the input string.
Signed-off-by: James Yonan <james@openvpn.net>
Linux has a filename maximum of 255 chars, but we need to
be careful about the composition of the temporary filename
so that we don't exceed this limitation on the temporary,
even when the original is within the limit.
Signed-off-by: James Yonan <james@openvpn.net>
Wintun documentation clearly states that we must use auto-reset events in ring buffers.
Auto-reset sets event back to non-signalled state after calling WaitForSingleObject.
Without auto-reset and explicit ResetEvent call we got a busy loop.
To avoid confusion move event.hpp from common/ to win/, since it is
Windows-specific code.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
This avoid a linkage problem encountered when building core with two
compilation units and OPENVPN_EXTERN being used.
Also adjust core unit tests with regard to now different extern usage
This allows to run openvpn under normal user account,
in which case ring buffers registration is performed
by a separate privileged process.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Added LogSetup, an abstract base class with a virtual method
reopen() that accomplishes the log file reopen.
Added RunContext::set_log_reopen() method that accepts
a LogSetup object and calls its reopen() method on
SIGHUP.
daemonize() and log_setup() methods in daemon.hpp
now return a LogSetup object.
Signed-off-by: James Yonan <james@openvpn.net>
MSF::find() is like ordinary map/set find(), but returns an
iterator that defines an operator bool() method for testing
if the iterator is defined, e.g.:
std::map<std::string, std::string> m;
m.emplace("hello", "world");
auto e = MSF::find(m, "hello");
if (e)
std::cout << e->first << " -> " << e->second << std::endl;
Signed-off-by: James Yonan <james@openvpn.net>
This uses Windows-specific wchar_t override of std::ifstream
to make it work with UNICODE paths. It is assumed that caller
passes UTF8-encoded string.
To support passing non-ASCII chars via command line, we
read it as wstring and then convert to UTF-8 encoded string.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Without this fix, some gcc compilers will issue the warning below when
building the reference client:
../../openvpn/common/base64.hpp: In constructor
‘openvpn::Base64::UCharWrap::UCharWrap(unsigned char*, size_t)’:
../../openvpn/common/base64.hpp:77:9: warning:
‘openvpn::Base64::UCharWrap::size’ will be initialized after [-Wreorder]
size_t size;
^
../../openvpn/common/base64.hpp:76:17: warning: ‘unsigned char*
openvpn::Base64::UCharWrap::data’ [-Wreorder]
unsigned char *data;
^
../../openvpn/common/base64.hpp:63:2: warning: when initialized here
[-Wreorder]
UCharWrap(unsigned char *data, size_t size):
^
This patch fixes this issue as well as removing a redundant public
declaration and fixing some whitespace issues.
Signed-off-by: David Sommerseth <davids@openvpn.net>
NodeJS C++ environment defines ssize_t and causes
core build to fail because of type redefinition.
To fix, surround core's definition with same #ifdef guards
used in Node.JS.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
* schwabe/UCONNECT-1186-fix-custom-memcpy:
Replace custom memcpy implementation
Workaround for compiler bug in memneq
[UCONNECT-1027] use one AsioWork object for the whole pre-resolve opertation
Revert "[UCONNECT-1027] remotelist: create standalone object for resolve thread"
Signed-off-by: Arne Schwabe <arne@openvpn.net>
bigmutex.hpp relies on OPENVPN_EXTERN and therefore it must include
extern.hpp so that it can get defined when not specified elsewhere.
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
When building for big-endian machines, it fails with
openvpn/common/endian.hpp:65:28: error: #elif with no expression
# elif OPENVPN_BIG_ENDIAN
^
This is resolved by adding defined(). Also did the same for the first
for consistency.
Signed-off-by: David Sommerseth <davids@openvpn.net>
When we define OPENVPN_EXTERNAL_TRANSPORT_FACTORY, we also use
OPENVPN_LOG_NTNL macro:
ovpncli.cpp -> ovpncli.hpp -> extern/fw.hpp -> transbase.hpp -> protocol.hpp -> options.hpp
The problem is that macro is defined after ovpncli.hpp is included.
To fix this, we break link between protocol.hpp and options.hpp by moving option_error
into separate include file, which we include from protocol.hpp (instead of options.hpp) and
options.hpp.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
1. include <type_traits>
2. make operator() method const
3. use SFINAE and std::enable_if to choose between Intern and Extern
4. use rvalue references in passed arguments whenever possible
Signed-off-by: James Yonan <james@openvpn.net>
Fix warnings reported by LLVM/Clang
Approved-by: David Sommerseth <davids@openvpn.net>
Approved-by: Lev Stipakov <lev@openvpn.net>
Approved-by: James Yonan <james@openvpn.net>
To bundle ptcore and openvpncli into the same shared library for
OpenVPN Connect, the two libraries need both to include OpenVPN (or
parts of it).
Ptcore defines OPENVPN_EXTERN as extern to define the symbols as extern
in that library but a few places are missing proper weak symbol (inline)
or extern declaration.
This file contains generic functions for parsing and rendering various
data types to/from hexadecimal strings. This patch just adds generic
documentation to all functions and the RenderHexByte class.
Signed-off-by: David Sommerseth <davids@openvpn.net>
---
v2 - Improved and clarified serveral aspects raised by Antonio
Platforms like UWP and iOS may call core methods
from another threads. Since core is not thread-safe,
we provide OPENVPN_ASYNC_HANDLER macro which instantiates
lock guard. It follows RAII principle and locks global
mutex in constructor and unlocks in destructor. This
guarantees that code in block protected with this macro
won't be called simultaneously from different threads.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
This branch is targeted for consumers of the library, where we will do
release handling. This branch should contain reasonably well tested and
stable code only. Features under development and testing should only be
worked on outside of this branch until it is ready and can be merged
into stable.
Since it has been quite some time since the version.hpp file was
updated, this change will now set version to 3.2 - to start this new
versioning regime.
The version numbering and release process is further described in
VersionNumbering.rst
Signed-off-by: David Sommerseth <davids@openvpn.net>
Allow source files that require JSON library functionality
to include a single file (openvpn/common/jsonlib.hpp) which
will then draw in the appropriate JSON library header based
on configuration #defines.
Code can #ifdef on HAVE_JSON to test whether or not JSON
functionality is available (previously, HAVE_JSONCPP
was used).
Currently supports JsonCpp and an OpenVPN-internal JSON
implementation.
This model assumes that alternative JSON implementations
are API-compatible with JsonCpp.
Signed-off-by: James Yonan <james@openvpn.net>
Change the OPENVPN_EXIT_IN compile-time flag to be
a run-time option instead, controllable via the
EXIT_IN env var. Set EXIT_IN to the number of
seconds to run before exiting.
Signed-off-by: James Yonan <james@openvpn.net>
std::strerror() doesn't claim to be thread-safe, so
add openvpn::strerror_str() which is thread-safe by
virtue of the fact that it backs to strerror_r().
Signed-off-by: James Yonan <james@openvpn.net>
A common AsioTimer usage pattern is:
expires_at(Time::now() + duration)
This is more succinctly and efficiently stated as:
expires_after(duration).
Signed-off-by: James Yonan <james@openvpn.net>
* Automatically overflow to dynamic allocation if function
object is too large.
* Added optional N and INTERN_ONLY parameters to fine-tune
internal allocation.
* Added default constructor.
* Added move assignment method.
* Added reset() methods.
* Added operator bool() method to test if functor has
been defined.
Signed-off-by: James Yonan <james@openvpn.net>
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.
The basic approach is to rename all references to asio::xxx
types to openvpn_io::xxx and then make openvpn_io a
preprocessor variable that points to the top-level namespace
of the i/o reactor implementation.
All of the source files that currently include <asio.hpp> now
include <openvpn/io/io.hpp> instead:
This gives us a lightweight abstraction layer that allows us
to define openvpn_io to be something other than asio.
Other changes:
* Inclusion of asio by scripts/build is now optional, and is
enabled by passing ASIO=1 or ASIO_DIR=<dir>.
* Refactored openvpn/common/socktypes.hpp to no longer
require asio.
* Refactored openvpn/log/logthread.hpp to no longer require
asio.
* Added openvpn::get_hostname() method as alternative to
calling asio directly.
* openvpn/openssl/util/init.hpp will now #error
if USE_ASIO is undefined.
Signed-off-by: James Yonan <james@openvpn.net>
user-defined service objects. This commit attempts
to work around that but requires a specially patched
version of Asio that includes the virtual
async_connect_post_open() method.