Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed: accept empty strings for the Input.SendText JSON-RPC call, as …
…they are perfectly valid input
  • Loading branch information
bobo1on1 committed Oct 13, 2012
1 parent 7493741 commit b23adb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions xbmc/interfaces/json-rpc/InputOperations.cpp
Expand Up @@ -94,16 +94,18 @@ JSONRPC_STATUS CInputOperations::activateWindow(int windowID)


JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result) JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{ {
std::string text = parameterObject["text"].asString(); const CVariant& textvar = parameterObject["text"];
if (text.empty()) if (!textvar.isString())
return InvalidParams; return InvalidParams;


std::string textstr = textvar.asString();

CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow()); CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
if (!window) if (!window)
return InternalError; return InternalError;


CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0); CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0);
msg.SetLabel(text); msg.SetLabel(textstr);
msg.SetParam1(parameterObject["done"].asBoolean() ? 1 : 0); msg.SetParam1(parameterObject["done"].asBoolean() ? 1 : 0);
CApplicationMessenger::Get().SendGUIMessage(msg, window->GetID()); CApplicationMessenger::Get().SendGUIMessage(msg, window->GetID());
return ACK; return ACK;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -2747,7 +2747,7 @@ namespace JSONRPC
"\"transport\": \"Response\"," "\"transport\": \"Response\","
"\"permission\": \"Navigate\"," "\"permission\": \"Navigate\","
"\"params\": [" "\"params\": ["
"{ \"name\": \"text\", \"type\": \"string\", \"minLength\": 1, \"required\": true, \"description\": \"Unicode text\" }," "{ \"name\": \"text\", \"type\": \"string\", \"required\": true, \"description\": \"Unicode text\" },"
"{ \"name\": \"done\", \"type\": \"boolean\", \"default\": true, \"description\": \"Whether this is the whole input or not (closes an open input dialog if true).\" }" "{ \"name\": \"done\", \"type\": \"boolean\", \"default\": true, \"description\": \"Whether this is the whole input or not (closes an open input dialog if true).\" }"
"]," "],"
"\"returns\": \"string\"" "\"returns\": \"string\""
Expand Down

2 comments on commit b23adb3

@Montellese
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the extra CVariant and the check whether it's a string or not. CJSONServiceDescription takes care of that and will throw an error at the JSON-RPC client if the "text" parameter is not a string. So basically you could have just dropped the

if (text.empty())
  return InvalidParams;

part. Plus you also need to make the same change you did to ServiceDescription.h in methods.json. I'll fix it up, just as an FYI.

@bobo1on1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crap.

Please sign in to comment.