Core/RPC: XMLRPC now can support i8 type

git-svn-id: svn://ultimatepp.org/upp/trunk@12642 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-01-03 10:58:01 +00:00
parent e400f2f875
commit 537f9feb40
9 changed files with 57 additions and 23 deletions

View file

@ -34,6 +34,7 @@ struct RawJsonText {
void ValueCheck(bool b);
void ValueGet(int& n, const Value& v);
void ValueGet(int64& n, const Value& v);
void ValueGet(bool& b, const Value& v);
void ValueGet(String& s, const Value& v);
void ValueGet(double& x, const Value& v);
@ -112,6 +113,7 @@ void ValueGet(VectorMap<int, T>& x, const Value& v)
}
void ValuePut(Value& v, int n);
void ValuePut(Value& v, int64 n);
void ValuePut(Value& v, const String& s);
void ValuePut(Value& v, const char *s);
void ValuePut(Value& v, double x);
@ -248,9 +250,9 @@ private:
XmlRpcDo *rpc;
};
String FormatXmlRpcValue(const Value& value);
String FormatXmlRpcParam(const Value& param);
String FormatXmlRpcParams(const ValueArray& params);
String FormatXmlRpcValue(const Value& _v, bool supports_i8);
String FormatXmlRpcParam(const Value& param, bool supports_i8);
String FormatXmlRpcParams(const ValueArray& params, bool supports_i8);
String FormatXmlRpcError(int code, const char *text);
@ -280,6 +282,7 @@ class RpcRequest : public HttpRequest {
int faultCode;
bool shouldExecute;
bool json, notification;
bool supports_i8;
String protocol_version;
void Init();
@ -330,7 +333,7 @@ public:
RpcRequest& JsonRpc() { json = true; return *this; }
RpcRequest& Notification() { notification = true; return *this; }
RpcRequest& ProtocolVersion(const char *s) { protocol_version = s; return *this; }
RpcRequest& SupportsI8() { supports_i8 = true; protocol_version = "2.1"; return *this; }
RpcRequest(const char *url);
RpcRequest();

View file

@ -44,6 +44,7 @@ void RpcRequest::Init()
RequestTimeout(30000);
MaxRetries(0);
json = false;
supports_i8 = false;
}
RpcRequest::RpcRequest(const char *url)
@ -121,8 +122,8 @@ RpcGet RpcRequest::Execute()
ContentType("text/xml");
request = XmlHeader();
if(protocol_version.GetCount())
request << "<!--protocolVersion=\\\"" << protocol_version << "\\\"-->\r\n";
request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out));
request << "<!--protocolVersion=\"" << protocol_version << "\"-->\r\n";
request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out, supports_i8));
}
if(sLogRpcCalls) {
if(sLogRpcCallsCompress)
@ -202,6 +203,8 @@ RpcGet RpcRequest::Execute()
XmlParser p(response);
try {
p.ReadPI();
while(p.IsComment())
p.ReadComment();
p.PassTag("methodResponse");
if(p.Tag("fault")) {
Value m = ParseXmlRpcValue(p);

View file

@ -136,7 +136,7 @@ String XmlRpcDo::XmlResult()
*rpc_trace << "Processing error: " << e << '\n';
return FormatXmlRpcError(RPC_SERVER_PROCESSING_ERROR, "Processing error: " + e);
}
r << FormatXmlRpcParams(data.out);
r << FormatXmlRpcParams(data.out, false);
}
r << "\r\n</methodResponse>\r\n";
return r;

View file

@ -40,6 +40,12 @@ void ValueGet(int& n, const Value& v)
n = v;
}
void ValueGet(int64& n, const Value& v)
{
ValueCheck(IsNull(v) || IsNumber(v));
n = v;
}
void ValueGet(String& s, const Value& v)
{
ValueCheck(IsNull(v) || IsString(v));
@ -108,6 +114,11 @@ void ValuePut(Value& v, int n)
v = n;
}
void ValuePut(Value& v, int64 n)
{
v = n;
}
void ValuePut(Value& v, const String& s)
{
v = s;

View file

@ -15,6 +15,14 @@ Value ParseXmlRpcValue(XmlParser& p)
r = p.ReadInt();
}
else
if(p.Tag("i8")) {
String s = p.ReadText();
CParser p(s);
if(!p.IsInt())
throw XmlError("integer expected");
r = p.ReadInt64();
}
else
if(p.Tag("boolean")) {
int n = StrInt(p.ReadText());
if(n != 0 && n != 1)
@ -97,11 +105,11 @@ ValueArray ParseXmlRpcParams(XmlParser& p)
return va;
}
String FormatXmlRpcValue(const Value& _v)
String FormatXmlRpcValue(const Value& _v, bool supports_i8)
{
String r;
Value v = _v;
if(v.GetType() == INT64_V) {
if(v.GetType() == INT64_V && !supports_i8) {
int64 x = v;
if((int)x == x)
v = (int)x;
@ -109,6 +117,9 @@ String FormatXmlRpcValue(const Value& _v)
if(IsNull(v) && !IsString(v) && !IsValueArray(v))
r = XmlTag("nil")();
else
if(v.GetType() == INT64_V && supports_i8)
r = XmlTag("i8")(AsString((int64)v));
else
if(v.GetType() == INT_V)
r = XmlTag("int")(Format("%d", (int)v));
else
@ -131,7 +142,7 @@ String FormatXmlRpcValue(const Value& _v)
const Index<Value>& k = vm.GetKeys();
ValueArray va = vm.GetValues();
for(int i = 0; i < k.GetCount(); i++)
r << XmlTag("member")(XmlTag("name")(k[i]) + FormatXmlRpcValue(va[i]));
r << XmlTag("member")(XmlTag("name")(k[i]) + FormatXmlRpcValue(va[i], supports_i8));
r << "</struct>";
}
else
@ -139,7 +150,7 @@ String FormatXmlRpcValue(const Value& _v)
r = "<array><data>";
ValueArray va = v;
for(int i = 0; i < va.GetCount(); i++)
r << FormatXmlRpcValue(va[i]);
r << FormatXmlRpcValue(va[i], supports_i8);
r << "</data></array>";
}
else
@ -150,17 +161,17 @@ String FormatXmlRpcValue(const Value& _v)
return XmlTag("value")(r);
}
String FormatXmlRpcParam(const Value& param)
String FormatXmlRpcParam(const Value& param, bool supports_i8)
{
return XmlTag("param")(FormatXmlRpcValue(param));
return XmlTag("param")(FormatXmlRpcValue(param, supports_i8));
}
String FormatXmlRpcParams(const ValueArray& params)
String FormatXmlRpcParams(const ValueArray& params, bool supports_i8)
{
String r;
r = "<params>";
for(int i = 0; i < params.GetCount(); i++)
r << FormatXmlRpcParam(params[i]);
r << FormatXmlRpcParam(params[i], supports_i8);
r << "</params>";
return r;
}

View file

@ -45,8 +45,12 @@ String DeXml(const String& s, byte charset, bool escapelf)
String XmlHeader(const char *encoding, const char *version, const char *standalone)
{
StringBuffer r;
r << "<?xml version=\"" << version << "\" encoding=\"" << encoding << "\" standalone=\""
<< standalone << "\" ?>\r\n";
r << "<?xml version=\"" << version << "\"";
if(encoding)
r << " encoding=\"" << encoding << "\"";
if(standalone)
r << " standalone=\"" << standalone << "\"";
r << " ?>\r\n";
return r;
}

View file

@ -2,7 +2,7 @@ String DeXml(const char *s, byte charset = CHARSET_DEFAULT, bool escapelf = fals
String DeXml(const char *s, const char *end, byte charset = CHARSET_DEFAULT, bool escapelf = false);
String DeXml(const String& s, byte charset = CHARSET_DEFAULT, bool escapelf = false);
String XmlPI(const char *text);
String XmlHeader(const char *encoding = "UTF-8", const char *version = "1.0", const char *standalone = "yes");
String XmlHeader(const char *encoding = "UTF-8", const char *version = "1.0", const char *standalone = NULL);
String XmlDecl(const char *text);
String XmlDocType(const char *text);
String XmlDoc(const char *name, const char *xmlbody);

View file

@ -1,5 +1,4 @@
topic "XML output";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
@ -9,6 +8,7 @@ topic "XML output";
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[2 $$0,0#00000000000000000000000000000000:Default]
[{_}
[ {{10000@(113.42.0) [s0;%% [*@7;4 XmlTag]]}}&]
[s3;%% &]
@ -101,8 +101,10 @@ to UTF`-8. If [*@3 escapelf].is true, `'`\n`' is escaped as `'[@(128.0.255) `&#x
[s5;:XmlHeader`(const char`*`,const char`*`,const char`*`): [_^String^ String]_[* XmlHead
er]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 encoding]_`=_`"UTF[@(0.0.255) `-][@3 8]`",
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 version]_`=_`"[@3 1][@(0.0.255) .][@3 0]`",
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 standalone]_`=_`"yes`")&]
[s2;%% Creates the header of XML file.&]
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 standalone]_`=_NULL)&]
[s2; [%% Creates the header of XML file. If ][*@3 version]_ is NULL,
it is not included, [*@3 standalone] can be either `"yes`" or `"no`"
or NULL (standalone attribute is then not included).&]
[s3;%% &]
[s4; &]
[s5;:XmlDecl`(const char`*`): [_^String^ String]_[* XmlDecl]([@(0.0.255) const]_[@(0.0.255) c
@ -130,4 +132,4 @@ har]_`*[*@3 text])&]
`*[*@3 text])&]
[s2;%% Creates the processing info element of XML.&]
[s3;%% &]
[s0; ]
[s0; ]]

View file

@ -811,7 +811,7 @@ ScrollBars::~ScrollBars() {}
void Scroller::Scroll(Ctrl& p, const Rect& rc, Point newpos, Size cellsize)
{
if(!IsNull(psb)) {
if(!IsNull(psb) && !p.IsTransparent()) {
Point d = psb - newpos;
p.ScrollView(rc, d.x * cellsize.cx, d.y * cellsize.cy);
}