new version "(34) Erndtebrück": remove apiVersion(), change version() to return a semver-compatible version number in a JSON object.

JSON-75-01
Lars Rohwedder 5 years ago
parent f6922d229a
commit 141d93ef50

@ -498,7 +498,7 @@ function init_pep_functions()
optionList += '<option' + (f.separator? ' disabled> —— ':'>') + f.name + "</option>\n";
}
document.getElementById("fn_name").innerHTML = optionList;
document.getElementById("spn_version").innerHTML = "version: " + server_version;
document.getElementById("spn_version").innerHTML = "version: " + server_version + " " + server_version_name;
}

@ -119,8 +119,7 @@ const FunctionMap functions = {
// my own example function that does something useful. :-)
FP( "Other", new Separator ),
FP( "version", new Func<std::string>( &JsonAdapter::version ) ),
FP( "apiVersion", new Func<unsigned> ( &JsonAdapter::apiVersion ) ),
FP( "version", new Func<ServerVersion>( &JsonAdapter::version ) ),
FP( "getGpgEnvironment", new Func<GpgEnvironment>( &getGpgEnvironment ) ),
FP( "shutdown", new Func<void, In<JsonAdapter*, false>>( &JsonAdapter::shutdown_now ) ),
@ -209,6 +208,7 @@ void ev_server::OnOtherRequest(evhttp_request* req, void*)
// generate a JavaScript file containing the definition of all registered callable functions, see above.
void ev_server::OnGetFunctions(evhttp_request* req, void*)
{
static const auto& version = server_version();
static const std::string preamble =
"var Direction = { In:1, Out:2, InOut:3 };\n"
"var Type = {\n"
@ -223,7 +223,8 @@ void ev_server::OnGetFunctions(evhttp_request* req, void*)
" Session : 90 // opaque type. only a special encoded 'handle' is used in JavaScript code\n"
" };\n"
"\n"
"var server_version = \"" + server_version + "\";\n"
"var server_version_name = \"" + version.name + "\";\n"
"var server_version = \"" + version.major_minor_patch() + "\";\n"
"var pep_functions = ";
js::Array jsonfunctions;

@ -320,16 +320,12 @@ In<JsonAdapter*, false>::~In()
}
std::string JsonAdapter::version()
ServerVersion JsonAdapter::version()
{
return server_version;
return server_version();
}
unsigned JsonAdapter::apiVersion()
{
return API_VERSION;
}

@ -5,6 +5,8 @@
#include <pEp/sync.h>
#include "registry.hh"
#include "context.hh"
#include "server_version.hh"
class JsonAdapter : public Context
{
@ -57,12 +59,9 @@ public:
virtual void augment(json_spirit::Object& returnObject) override;
// returns the version of the JsonAdapter
static
unsigned apiVersion();
// returns a version name
static
std::string version();
ServerVersion version();
static PEP_STATUS messageToSend(void* obj, message* msg);
static PEP_STATUS notifyHandshake(void* obj, pEp_identity* self, pEp_identity* partner, sync_handshake_signal signal);

@ -27,8 +27,7 @@ unsigned end_port = 9999;
void print_version()
{
std::cout << "pEp JSON Adapter.\n"
"\tversion \"" << JsonAdapter::version() << "\"\n"
"\tAPI version " << JsonAdapter::apiVersion() << "\n"
"\tversion " << JsonAdapter::version() << "\n"
"\tpEpEngine version " << get_engine_version() << "\n"
"\n";
}

@ -1,8 +1,11 @@
#include "server_version.hh"
#include "inout.hh"
namespace {
// version names comes from here:
// https://de.wikipedia.org/wiki/Bundesautobahn_4
const std::string server_version =
static const std::string version_name =
// "(4) Kreuz Aachen"; // first version with this version scheme :-)
// "(5a) Eschweiler-West"; // add support for log_event() and trustwords()
// "(5b) Eschweiler-Ost"; // add support for get_identity() and get_languagelist()
@ -37,4 +40,47 @@ const std::string server_version =
// "(30) Krombach"; // JSON-49, add call_with_lock() around init() and release().
// "(31) Altenkleusheim"; // JSON-57: change location of server token file. breaking API change, so API_VERSION=0x0003.
// "(32) Littfeld"; // JSON-72: add is_pep_user() to the API
"(33) Hilchenbach"; // JSON-71: Setup C++11 Multi-threading in libevent properly to avoid deadlocks in MT server code"
// "(33) Hilchenbach"; // JSON-71: Setup C++11 Multi-threading in libevent properly to avoid deadlocks in MT server code"
"(34) Erndtebrück"; // remove apiVersion(), change version() to return a semver-compatible version number in a JSON object.
const ServerVersion sv{0, 10, 0, version_name}; // first version defined.
} // end of anonymous namespace
////////////////////////////////////////////////////////////////////////////
const ServerVersion& server_version()
{
return sv;
}
std::string ServerVersion::major_minor_patch() const
{
return std::to_string(major) + "."
+ std::to_string(minor) + "."
+ std::to_string(patch);
}
std::ostream& operator<<(std::ostream& o, const ServerVersion& sv)
{
return o << sv.major_minor_patch() << " \"" << sv.name << '\"';
}
template<>
js::Value to_json<ServerVersion>(const ServerVersion& sv)
{
js::Object o;
o.emplace_back("major", uint64_t(sv.major));
o.emplace_back("minor", uint64_t(sv.minor));
o.emplace_back("patch", uint64_t(sv.patch));
o.emplace_back("version", sv.major_minor_patch());
o.emplace_back("name", sv.name);
return o;
}
template<>
js::Value Type2String<ServerVersion>::get() { return "ServerVersion"; }

@ -2,7 +2,27 @@
#define SERVER_VERSION_HH
#include <string>
#include <ostream>
extern const std::string server_version;
struct ServerVersion
{
unsigned major;
unsigned minor;
unsigned patch;
// This version name is updated from time to time when some "important" changes are made.
// The version name is of the form "(##) name" where ## is a monotonic increasing number.
std::string name;
// returns "major.minor.patch"
std::string major_minor_patch() const;
};
const ServerVersion& server_version();
std::ostream& operator<<(std::ostream& o, const ServerVersion&);
#endif //SERVER_VERSION_HH

Loading…
Cancel
Save