Skip to content

Commit

Permalink
JSONRPC: Fixed reaction on incoming announcements from clients
Browse files Browse the repository at this point in the history
An incoming announcement will execute the called method but not return a response (nothing over TCP and an empty HTTP 200 response over HTTP)
  • Loading branch information
Montellese authored and topfs2 committed Jan 26, 2011
1 parent 7ac97c2 commit 625699d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions xbmc/interfaces/json-rpc/JSONRPC.cpp
Expand Up @@ -320,9 +320,12 @@ CStdString CJSONRPC::MethodCall(const CStdString &inputString, ITransportLayer *

JSON_STATUS errorCode = OK;
Reader reader;
bool isAnnouncement = false;

if (reader.parse(inputString, inputroot) && IsProperJSONRPC(inputroot))
{
isAnnouncement = !inputroot.isMember("id");

CStdString method = inputroot.get("method", "").asString();
method = method.ToLower();
errorCode = InternalMethodCall(method, inputroot, result, transport, client);
Expand All @@ -334,7 +337,7 @@ CStdString CJSONRPC::MethodCall(const CStdString &inputString, ITransportLayer *
}

outputroot["jsonrpc"] = "2.0";
outputroot["id"] = inputroot.get("id", 0);
outputroot["id"] = inputroot.isObject() && inputroot.isMember("id") ? inputroot["id"] : Value();

switch (errorCode)
{
Expand Down Expand Up @@ -371,7 +374,9 @@ CStdString CJSONRPC::MethodCall(const CStdString &inputString, ITransportLayer *
}

StyledWriter writer;
CStdString str = writer.write(outputroot);
CStdString str;
if (!isAnnouncement)
str = writer.write(outputroot);
return str;
}

Expand All @@ -391,7 +396,7 @@ JSON_STATUS CJSONRPC::InternalMethodCall(const CStdString& method, Value& o, Val

inline bool CJSONRPC::IsProperJSONRPC(const Json::Value& inputroot)
{
return inputroot.isObject() && inputroot.isMember("jsonrpc") && inputroot["jsonrpc"].isString() && inputroot.get("jsonrpc", "-1").asString() == "2.0" && inputroot.isMember("method") && inputroot["method"].isString() && inputroot.isMember("id");
return inputroot.isObject() && inputroot.isMember("jsonrpc") && inputroot["jsonrpc"].isString() && inputroot.get("jsonrpc", "-1").asString() == "2.0" && inputroot.isMember("method") && inputroot["method"].isString();
}

inline const char *CJSONRPC::PermissionToString(const OperationPermission &permission)
Expand Down

0 comments on commit 625699d

Please sign in to comment.