registerSession shall use security_token, too. fix some warnings clang++ shows but gcc does not.

no_SessionID_in_API
Roker 7 years ago
parent 6d3f19a2be
commit 0885bdd164

@ -241,10 +241,11 @@ function createSession()
{
var url = document.getElementById("server").value + 'createSession';
var request = {};
request.method = 'createSession';
request.params = [':-)'];
request.id = ++call_ID;
request.jsonrpc = "2.0";
request.security_token = document.getElementById("security_token").value;
request.method = 'createSession';
request.params = [];
var x = $.post(url, JSON.stringify(request), null, "json")
.done(function(data, status, xhr) {
openSessions.push(data);
@ -261,10 +262,11 @@ function getAllSessions()
{
var url = document.getElementById("server").value + 'getAllSessions';
var request = {};
request.method = 'getAllSessions';
request.params = {};
request.id = ++call_ID;
request.jsonrpc = "2.0";
request.security_token = document.getElementById("security_token").value;
request.method = 'getAllSessions';
request.params = [];
var x = $.post(url, JSON.stringify(request), null, "json")
.done(function(data, status, xhr) {
openSessions = data;
@ -297,6 +299,15 @@ function displayResult(response)
}
function pc(c)
{
if(c>32 && c<127)
{
return '“' + String.fromCharCode(c) + '|' + c + '”';
}else
return '(' + c + ')';
}
function button_click()
{
var deb = document.getElementById("debug");
@ -306,6 +317,8 @@ function button_click()
var url = document.getElementById("server").value + 'callFunction';
var request = {};
request.id = ++call_ID;
request.jsonrpc = "2.0";
request.security_token = document.getElementById("security_token").value;
request.method = document.getElementById("fn_name").value;
request.params = new Array(func.params.length);
@ -326,8 +339,6 @@ function button_click()
}
}
request.id = ++call_ID;
request.jsonrpc = "2.0";
var x = $.post(url, JSON.stringify(request), null, "json")
.done(function(moo) {
displayResult(moo);
@ -339,6 +350,25 @@ function button_click()
+ "Text: " + JSON.stringify(txt, null, 2) + "\n"
+ "Error:" + JSON.stringify(err, null, 2) + "\n";
// HACK to try to parse hdr.responseText:
var rt = hdr.responseText;
if($.type(rt) === 'string')
{
try{
var j = JSON.parse(rt);
emsg += "Header.responseText: " + JSON.stringify(j, null, 2) + "\n";
}
catch(e)
{
emsg += "Header.responseText cannot be parsed: " + e + "\n";
for(var i=0; i<200; ++i)
{
emsg += i + ":" + pc(rt.charCodeAt(i)) + ', ';
}
emsg += "\n";
}
}
var pre = document.getElementById("resultpre");
pre.innerHTML += emsg;
pre.className = "red";

@ -21,20 +21,12 @@ In<char const*>::~In()
if(value) free(const_cast<char*>(value));
}
template<>
In<int>::~In()
{ }
template<>
In<time_t>::~In()
{ }
template<>
In<std::size_t>::~In()
{ }
#define SIMPLE_TYPE_OUT(TYPE) \
#define SIMPLE_TYPE(TYPE) \
template<> \
In< TYPE >::~In() \
{ } \
\
template<> \
Out< TYPE >::~Out() \
{ \
@ -42,10 +34,16 @@ In<std::size_t>::~In()
} \
SIMPLE_TYPE_OUT( bool )
SIMPLE_TYPE_OUT( unsigned )
SIMPLE_TYPE_OUT( unsigned long)
SIMPLE_TYPE_OUT( unsigned long long)
SIMPLE_TYPE( bool )
SIMPLE_TYPE( unsigned short )
SIMPLE_TYPE( unsigned )
SIMPLE_TYPE( unsigned long )
SIMPLE_TYPE( unsigned long long )
SIMPLE_TYPE( short )
SIMPLE_TYPE( int )
SIMPLE_TYPE( long )
SIMPLE_TYPE( long long )
template<>
@ -71,7 +69,6 @@ Out<char*>::~Out()
}
template<>
int from_json<int>(const js::Value& v)
{
@ -79,16 +76,46 @@ int from_json<int>(const js::Value& v)
}
template<>
unsigned from_json<unsigned>(const js::Value& v)
bool from_json<bool>(const js::Value& v)
{
return v.get_uint64();
return v.get_bool();
}
template<>
time_t from_json<time_t>(const js::Value& v)
{
return static_cast<time_t>(v.get_int64());
}
#define FROM_TO_JSON_UINT64( TYPE ) \
template<> \
TYPE from_json<TYPE>(const js::Value& v) \
{ \
return v.get_uint64(); \
} \
\
template<> \
js::Value to_json< TYPE >(const TYPE& t) \
{ \
return js::Value(uint64_t(t)); \
}
FROM_TO_JSON_UINT64( unsigned )
FROM_TO_JSON_UINT64( unsigned long )
FROM_TO_JSON_UINT64( unsigned long long )
#define FROM_TO_JSON_INT64( TYPE ) \
template<> \
TYPE from_json<TYPE>(const js::Value& v) \
{ \
return v.get_int64(); \
} \
\
template<> \
js::Value to_json< TYPE >(const TYPE& t) \
{ \
return js::Value(int64_t(t)); \
}
FROM_TO_JSON_UINT64( long )
FROM_TO_JSON_UINT64( long long )
template<>
std::string from_json<std::string>(const js::Value& v)
@ -121,12 +148,6 @@ template js::Value to_json<int>(const int&);
template js::Value to_json<std::string>(const std::string&);
template<>
js::Value to_json<unsigned>(const unsigned& t)
{
return js::Value(uint64_t(t));
}
template<>
js::Value to_json<char*>(char* const & s)
{
@ -139,17 +160,6 @@ js::Value to_json<const char*>(const char* const & s)
return s ? js::Value(std::string(s)) : js::Value{};
}
template<>
js::Value to_json<std::size_t>(const std::size_t& s)
{
return js::Value{uint64_t(s)};
}
template<>
std::size_t from_json<std::size_t>(const js::Value& v)
{
return v.get_uint64();
}
template<>
js::Value to_json<struct tm*>(struct tm* const& t)
@ -165,12 +175,6 @@ js::Value to_json<struct tm*>(struct tm* const& t)
}
template<>
bool from_json<bool>(const js::Value& v)
{
return v.get_bool();
}
template<>
js::Value Type2String<std::string>::get() { return "String"; }

@ -23,11 +23,6 @@ T from_json(const js::Value& v);
template<class T>
js::Value to_json(const T& t);
template<class T>
js::Value to_json(const Out<T>& t);
// helper classes to specify in- and out-parameters
template<class T>
@ -40,8 +35,7 @@ struct In
~In();
In(const In<T>& other) = delete;
In(In<T>&& victim);
In(In<T>&& victim) = delete;
In<T>& operator=(const In<T>&) = delete;
// default implementation:
@ -69,7 +63,7 @@ struct InRaw
~InRaw() = default;
InRaw(const InRaw<T>& other) = delete;
InRaw(InRaw<T>&& victim);
InRaw(InRaw<T>&& victim) = delete;
InRaw<T>& operator=(const InRaw<T>&) = delete;
// default implementation:
@ -127,7 +121,7 @@ struct Out
~Out();
Out(const Out<T>& other) = delete;
Out(Out<T>&& victim);
Out(Out<T>&& victim) = delete;
// just to be sure they are not implicitly defined:
Out<T>& operator=(const Out<T>& other) = delete;
@ -149,7 +143,8 @@ struct Out
{
o << (const void*)&out;
if(&out)
// the if() was added to avoid crashes on memory corruptuon. But clang++ warns, that this check is always true on "well-formed" programs, and he is right. In an ideal world there are no memory corruptions. ;-(
// if(&out)
{
o << ", value=" << (const void*)out.value;
if(out.value)

@ -8,12 +8,12 @@ namespace js = json_spirit;
enum class JSON_RPC
{
PARSE_ERROR = -32700,
INVALID_REQUEST = -32600,
PARSE_ERROR = -32700,
INVALID_REQUEST = -32600,
METHOD_NOT_FOUND = -32601,
INVALID_PARAMS = -32602,
INVALID_PARAMS = -32602,
INTERNAL_ERROR = -32603,
INTERNAL_ERROR = -32603,
};

@ -587,7 +587,7 @@ namespace json_spirit
return internal_::get_value( *this, internal_::Type_to_type< T >() );
}
static std::string value_type_to_string( const Value_type vtype )
static inline std::string value_type_to_string( const Value_type vtype )
{
switch( vtype )
{

@ -165,7 +165,7 @@ bool isNFC(const std::string& s)
std::string toNFC(std::string s)
{
if(isNFC(s))
return std::move(s);
return s;
std::string ret;

@ -302,7 +302,7 @@ _bloblist_t* from_json<_bloblist_t*>(const js::Value& v)
const auto oelem = element->get_obj();
_bloblist_t* bl = new_bloblist
(
from_json_object<char*, js::str_type> (oelem, "data"),
from_json_object<char*, js::str_type> (oelem, "value"),
from_json_object<size_t, js::int_type> (oelem, "size"),
from_json_object<const char*, js::str_type>(oelem, "mime_type"),
from_json_object<const char*, js::str_type>(oelem, "filename")
@ -312,7 +312,7 @@ _bloblist_t* from_json<_bloblist_t*>(const js::Value& v)
{
const auto oelem = element->get_obj();
bl = bloblist_add(bl,
from_json_object<char*, js::str_type> (oelem, "data"),
from_json_object<char*, js::str_type> (oelem, "value"),
from_json_object<size_t, js::int_type> (oelem, "size"),
from_json_object<const char*, js::str_type>(oelem, "mime_type"),
from_json_object<const char*, js::str_type>(oelem, "filename")
@ -451,7 +451,7 @@ js::Value to_json<pEp_identity*>(pEp_identity* const& id)
o.emplace_back( "comm_type", js::Value( int( id->comm_type) ));
if(id->lang && id->lang[0] && id->lang[1])
if(id->lang[0] && id->lang[1])
o.emplace_back( "lang", js::Value( std::string( id->lang, id->lang+2) ));
o.emplace_back( "me", js::Value( id->me ));

Loading…
Cancel
Save