new version "(23) Engelskirchen": fix JSON-19. Support "Bool" and "Language" as separate data types in JavaScript.

ENGINE-187
Roker 6 years ago
parent 56ace2ef87
commit c352ebb132

@ -101,7 +101,26 @@ var Param2Form =
return 'Bool: <input type="checkbox" id="inp_param_' + nr + '" value="' + value + '" >';
}
},
Language : function(nr, pp, value)
{
if(pp.direction=="Out")
{
return 'Language output';
}else{
return '<label>Language: <select id="inp_param_' + nr + '" size="1">'
/* TODO: generate that list dynamically via get_languagelist() */
+ '<option value="ca">Català</option>'
+ '<option value="de">Deutsch</option>'
+ '<option value="en">English</option>'
+ '<option value="es">Español</option>'
+ '<option value="fr">Français</option>'
+ '<option value="tr">Türkçe</option>'
+ '<option value="ru">Русский</option>'// russian - no trustwords, yet
+ '<option value="zh">中文</option>' // chinese - no trustwords, yet
+ '</select></label>';
}
},
StringList : function(nr, pp, value)
{
if(pp.direction=="Out")
@ -246,6 +265,10 @@ var Form2Param =
{
return document.getElementById( 'inp_param_' + nr ).checked;
},
Language: function(nr, pp, value)
{
return document.getElementById( 'inp_param_' + nr ).value;
},
StringList : function(nr, pp, value)
{
var ret = [];

@ -50,6 +50,8 @@ struct In
return ::to_json<T>(value);
}
c_type get_value() const { return value; }
T value;
};
@ -78,6 +80,8 @@ struct InRaw
throw std::logic_error( std::string(typeid(T).name()) + " is not for output!" );
}
c_type get_value() const { return value; }
js::Value value;
};
@ -138,6 +142,8 @@ struct Out
return ::to_json<T>(*value);
}
c_type get_value() const { return value; }
T* value = nullptr;
friend
@ -198,7 +204,7 @@ public:
static js::Value call( const std::function<R(typename Args::c_type...)>& fn, Context*, js::Array& out_parameters, const js::Array& parameters, const Args&... args)
{
return to_json( fn(args.value...) );
return to_json( fn(args.get_value()...) );
}
};
@ -218,7 +224,7 @@ public:
static js::Value call( const std::function<void(typename Args::c_type...)>& fn, Context*, js::Array& out_parameters, const js::Array& parameters, const Args&... args)
{
fn(args.value...);
fn(args.get_value()...);
return js::Value{};
}
};

@ -86,7 +86,8 @@ const std::string server_version =
// "(19) Bensberg"; // command-line parameters, daemonize(), silent all output in daemon mode
// "(20) Moitzfeld"; // showHandshake() -> notifyHandshake() and other Engine's API changes
// "(21) Untereschbach"; // JSON-11: replace trustwords() by get_trustwords()
"(22) Overath"; // add blacklist_retrieve(), rename identity_color() and outgoing_message_color() into ..._rating().
// "(22) Overath"; // add blacklist_retrieve(), rename identity_color() and outgoing_message_color() into ..._rating().
"(23) Engelskirchen"; // fix JSON-19. Support "Bool" and "Language" as separate data types in JavaScript.
typedef std::map<std::thread::id, PEP_SESSION> SessionRegistry;
@ -150,9 +151,9 @@ const FunctionMap functions = {
FP( "—— pEp Engine Core API ——", new Separator),
FP( "log_event", new Func<PEP_STATUS, In<PEP_SESSION,false>, In<const char*>, In<const char*>, In<const char*>, In<const char*>>( &log_event) ),
FP( "get_trustwords", new Func<PEP_STATUS, In<PEP_SESSION,false>, In<const pEp_identity*>, In<const pEp_identity*>, In<const char*>, Out<char*>, Out<size_t>, In<bool>>( &get_trustwords) ),
FP( "get_trustwords", new Func<PEP_STATUS, In<PEP_SESSION,false>, In<const pEp_identity*>, In<const pEp_identity*>, In<Language>, Out<char*>, Out<size_t>, In<bool>>( &get_trustwords) ),
FP( "get_languagelist", new Func<PEP_STATUS, In<PEP_SESSION,false>, Out<char*>>( &get_languagelist) ),
FP( "get_phrase" , new Func<PEP_STATUS, In<PEP_SESSION,false>, In<const char*>, In<int>, Out<char*>> ( &get_phrase) ),
FP( "get_phrase" , new Func<PEP_STATUS, In<PEP_SESSION,false>, In<Language>, In<int>, Out<char*>> ( &get_phrase) ),
FP( "get_engine_version", new Func<const char*> ( &get_engine_version) ),
FP( "config_passive_mode", new Func<void, In<PEP_SESSION,false>, In<bool>>( &config_passive_mode) ),
FP( "config_unencrypted_subject", new Func<void, In<PEP_SESSION,false>, In<bool>>( &config_unencrypted_subject) ),

@ -43,7 +43,8 @@ namespace
obj.emplace_back( key, js::Value( base64_encode( raw_string ) ) );
}
}
}
} // end of anonymous namespace
// in pEpEngine.h positive values are hex, negative are decimal. :-o
@ -659,4 +660,5 @@ js::Value Type2String<_PEP_comm_type>::get() { return "PEP_comm_type"; }
template<>
js::Value Type2String<PEP_STATUS>::get() { return "PEP_STATUS"; }
template<>
js::Value Type2String<Language>::get() { return "Language"; }

@ -10,4 +10,45 @@
// in pEpEngine.h positive values are hex, negative are decimal. :-o
std::string status_to_string(PEP_STATUS status);
// just a tag type:
struct Language{};
template<>
struct In<Language>
{
typedef const char* c_type; // the according type in C function parameter
enum { is_output = false, need_input = true };
~In() = default;
In(const In<Language>& other) = delete;
In(In<Language>&& victim) = delete;
void operator=(const In<Language>&) = delete;
// default implementation:
In<Language>(const js::Value& v, Context*)
{
const std::string vs = v.get_str();
if(vs.size() != 2)
{
throw std::runtime_error("Language must be a string of length 2, but I got \"" + vs + "\".");
}
array_value[0]=vs[0];
array_value[1]=vs[1];
array_value[2]='\0';
}
js::Value to_json() const
{
return js::Value( std::string(get_value(), get_value()+2) );
}
c_type get_value() const { return array_value; }
char array_value[3];
};
#endif // PEP_TYPES_HH

Loading…
Cancel
Save