0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00
openvpn3/openvpn/options/clihalt.hpp
James Yonan 6fb53c3abb Fixed a race condition issue with "hot connect", i.e. sending a
connect intent to service when already connected.  

One of the ramifications of the "hot connect" fix above is that
OpenVPNClientBase.is_active() will now return a value that is
instantaneously up-to-date, whereas events might lag because
of the mechanics of inter-thread message posting.  Keep this in
mind when correlating received events to is_active() values.

For C++ core threads, increased allowed thread-stop delay to 2.5
seconds before thread is marked as unresponsive and abandoned.
Previous delay was 1 second.  This delay can't be made too long,
otherwise Android will tell the user that the app is unresponsive
and invite them to kill it.

When closing out an abandoned core thread, indicate this condition
with a new event type called CORE_THREAD_ABANDONED.  If the thread
is abandoned due to lack of response to a disconnect request, then
the CORE_THREAD_ABANDONED event will occur followed by
CORE_THREAD_INACTIVE.  For core threads that properly exit,
the DISCONNECTED event will be followed by CORE_THREAD_INACTIVE.

Added save_as_filename parameter to importProfileRemote method for
controlling the filename that the imported profile is saved as.
This parameter may be set to null to have the method choose an
appropriate name.  To have an imported profile replace an existing
profile, the filenames much match.

Added UI_OVERLOADED debugging constant to OpenVPNClient to allow
the UI to connect to a profile when already connected to another
profile in order to test "hot connect".

Added new events CLIENT_HALT and CLIENT_RESTART for compatibility
with an Access Server feature that allows the server to remotely
kill or restart the client.

When connecting a profile, the core will now automatically fill in
the username if it is not specified for userlocked profiles.

Version 0.902.
2012-03-31 16:08:20 +00:00

98 lines
2.3 KiB
C++

#ifndef OPENVPN_OPTIONS_CLIHALT_H
#define OPENVPN_OPTIONS_CLIHALT_H
#include <string>
#include <sstream>
#include <vector>
#include <boost/algorithm/string.hpp> // for boost::algorithm::starts_with
#include <openvpn/common/exception.hpp>
#include <openvpn/common/split.hpp>
// Process halt/restart messages from server:
// HALT,<client_reason> -> disconnect
// RESTART,<client_reason> -> restart with reason, don't preserve session ID
// RESTART,[P]:<client_reason> -> restart with reason, do preserve session ID
namespace openvpn {
class ClientHalt
{
typedef std::vector<std::string> StringList;
public:
OPENVPN_SIMPLE_EXCEPTION(client_halt_error);
ClientHalt(const std::string& msg)
: restart_(false), psid_(false)
{
// get operator (halt or restart)
StringList sl;
parse_msg(sl, msg);
if (is_halt(sl))
;
else if (is_restart(sl))
restart_ = true;
else
throw client_halt_error();
// get flags and reason
if (sl.size() >= 2)
{
size_t reason_pos = 0;
if (restart_ && boost::algorithm::starts_with(sl[1], "[P]:"))
{
psid_ = true;
reason_pos = 4;
}
reason_ = sl[1].substr(reason_pos);
}
}
static bool match(const std::string& msg)
{
StringList sl;
parse_msg(sl, msg);
return is_halt(sl) || is_restart(sl);
}
// returns true for restart, false for halt
bool restart() const { return restart_; }
// returns true if session ID should be preserved
bool psid() const { return psid_; }
// returns user-visible reason string
const std::string& reason() const { return reason_; }
std::string render() const {
std::ostringstream os;
os << (restart_ ? "RESTART" : "HALT") << " psid=" << psid_ << " reason='" << reason_ << '\'';
return os.str();
}
private:
static void parse_msg(StringList& sl, const std::string& msg)
{
sl.reserve(2);
split_by_char_void<StringList, NullLex>(sl, msg, ',', 2);
}
static bool is_halt(const StringList& sl)
{
return sl.size() >= 1 && sl[0] == "HALT";
}
static bool is_restart(const StringList& sl)
{
return sl.size() >= 1 && sl[0] == "RESTART";
}
bool restart_;
bool psid_;
std::string reason_;
};
}
#endif