diff options
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj | 4 | ||||
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj.filters | 8 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/JSONServiceDescription.cpp | 6 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/Makefile | 1 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/ProfilesOperations.cpp | 142 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/ProfilesOperations.h | 35 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/ServiceDescription.h | 64 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/methods.json | 42 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/types.json | 18 |
9 files changed, 316 insertions, 4 deletions
diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index acd84b63ad..46f51df0b4 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -739,6 +739,7 @@ <ClCompile Include="..\..\xbmc\interfaces\json-rpc\JSONServiceDescription.cpp" /> <ClCompile Include="..\..\xbmc\interfaces\json-rpc\PlayerOperations.cpp" /> <ClCompile Include="..\..\xbmc\interfaces\json-rpc\PlaylistOperations.cpp" /> + <ClCompile Include="..\..\xbmc\interfaces\json-rpc\ProfilesOperations.cpp" /> <ClCompile Include="..\..\xbmc\interfaces\json-rpc\PVROperations.cpp" /> <ClCompile Include="..\..\xbmc\interfaces\json-rpc\SystemOperations.cpp" /> <ClCompile Include="..\..\xbmc\interfaces\json-rpc\VideoLibrary.cpp" /> @@ -1113,6 +1114,7 @@ <ClInclude Include="..\..\xbmc\interfaces\generic\LanguageInvokerThread.h" /> <ClInclude Include="..\..\xbmc\interfaces\generic\ScriptInvocationManager.h" /> <ClInclude Include="..\..\xbmc\interfaces\json-rpc\FavouritesOperations.h" /> + <ClInclude Include="..\..\xbmc\interfaces\json-rpc\ProfilesOperations.h" /> <ClInclude Include="..\..\xbmc\interfaces\json-rpc\PVROperations.h" /> <ClInclude Include="..\..\xbmc\interfaces\legacy\Addon.h" /> <ClInclude Include="..\..\xbmc\interfaces\legacy\AddonCallback.h" /> @@ -2996,4 +2998,4 @@ </VisualStudio> </ProjectExtensions> <Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" /> -</Project>
\ No newline at end of file +</Project> diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index da231f72a5..272f2c7897 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -3050,6 +3050,9 @@ <ClCompile Include="..\..\xbmc\addons\AddonCallbacksCodec.cpp"> <Filter>addons</Filter> </ClCompile> + <ClCompile Include="..\..\xbmc\interfaces\json-rpc\ProfilesOperations.cpp"> + <Filter>interfaces\json-rpc</Filter> + </ClCompile> <ClCompile Include="..\..\xbmc\GitRevision.cpp" /> <ClCompile Include="..\..\xbmc\cores\AudioEngine\Engines\ActiveAE\ActiveAE.cpp"> <Filter>cores\AudioEngine\Engines\ActiveAE</Filter> @@ -6005,6 +6008,9 @@ <ClInclude Include="..\..\xbmc\addons\AddonCallbacksCodec.h"> <Filter>addons</Filter> </ClInclude> + <ClInclude Include="..\..\xbmc\interfaces\json-rpc\ProfilesOperations.h"> + <Filter>interfaces\json-rpc</Filter> + </ClInclude> <ClInclude Include="..\..\xbmc\win32\PlatformInclude.h" /> <ClInclude Include="..\..\xbmc\cores\AudioEngine\Engines\ActiveAE\ActiveAE.h"> <Filter>cores\AudioEngine\Engines\ActiveAE</Filter> @@ -6060,4 +6066,4 @@ <Filter>interfaces\swig</Filter> </None> </ItemGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp index 074c2da26b..bc79a9275b 100644 --- a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp +++ b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp @@ -36,6 +36,7 @@ #include "XBMCOperations.h" #include "ApplicationOperations.h" #include "PVROperations.h" +#include "ProfilesOperations.h" #include "FavouritesOperations.h" using namespace std; @@ -163,6 +164,11 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = { { "PVR.Record", CPVROperations::Record }, { "PVR.Scan", CPVROperations::Scan }, +// Profiles operations + { "Profiles.GetProfiles", CProfilesOperations::GetProfiles}, + { "Profiles.GetCurrentProfile", CProfilesOperations::GetCurrentProfile}, + { "Profiles.LoadProfile", CProfilesOperations::LoadProfile}, + // System operations { "System.GetProperties", CSystemOperations::GetProperties }, { "System.EjectOpticalDrive", CSystemOperations::EjectOpticalDrive }, diff --git a/xbmc/interfaces/json-rpc/Makefile b/xbmc/interfaces/json-rpc/Makefile index 6dc3ae65f4..398effbf0a 100644 --- a/xbmc/interfaces/json-rpc/Makefile +++ b/xbmc/interfaces/json-rpc/Makefile @@ -10,6 +10,7 @@ SRCS=AddonsOperations.cpp \ JSONServiceDescription.cpp \ PlayerOperations.cpp \ PlaylistOperations.cpp \ + ProfilesOperations.cpp \ PVROperations.cpp \ SystemOperations.cpp \ VideoLibrary.cpp \ diff --git a/xbmc/interfaces/json-rpc/ProfilesOperations.cpp b/xbmc/interfaces/json-rpc/ProfilesOperations.cpp new file mode 100644 index 0000000000..3edb628649 --- /dev/null +++ b/xbmc/interfaces/json-rpc/ProfilesOperations.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "ProfilesOperations.h" +#include "ApplicationMessenger.h" +#include "guilib/LocalizeStrings.h" +#include "profiles/ProfilesManager.h" +#include "utils/md5.h" + +using namespace JSONRPC; + +JSONRPC_STATUS CProfilesOperations::GetProfiles(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) +{ + CFileItemList listItems; + + for (unsigned int i = 0; i < CProfilesManager::Get().GetNumberOfProfiles(); ++i) + { + const CProfile *profile = CProfilesManager::Get().GetProfile(i); + CFileItemPtr item(new CFileItem(profile->getName())); + item->SetArt("thumb", profile->getThumb()); + listItems.Add(item); + } + + HandleFileItemList("profileid", false, "profiles", listItems, parameterObject, result); + + for (CVariant::const_iterator_array propertyiter = parameterObject["properties"].begin_array(); propertyiter != parameterObject["properties"].end_array(); ++propertyiter) + { + if (propertyiter->isString() && + propertyiter->asString() == "lockmode") + { + for (CVariant::iterator_array profileiter = result["profiles"].begin_array(); profileiter != result["profiles"].end_array(); ++profileiter) + { + CStdString profilename = (*profileiter)["label"].asString(); + int index = CProfilesManager::Get().GetProfileIndex(profilename); + const CProfile *profile = CProfilesManager::Get().GetProfile(index); + LockType locktype = LOCK_MODE_UNKNOWN; + if (index == 0) + locktype = CProfilesManager::Get().GetMasterProfile().getLockMode(); + else + locktype = profile->getLockMode(); + (*profileiter)["lockmode"] = locktype; + } + break; + } + } + return OK; +} + +JSONRPC_STATUS CProfilesOperations::GetCurrentProfile(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) +{ + const CProfile& currentProfile = CProfilesManager::Get().GetCurrentProfile(); + CVariant profileVariant = CVariant(CVariant::VariantTypeObject); + profileVariant["label"] = currentProfile.getName(); + for (CVariant::const_iterator_array propertyiter = parameterObject["properties"].begin_array(); propertyiter != parameterObject["properties"].end_array(); ++propertyiter) + { + if (propertyiter->isString()) + { + if (propertyiter->asString() == "lockmode") + profileVariant["lockmode"] = currentProfile.getLockMode(); + else if (propertyiter->asString() == "thumbnail") + profileVariant["thumbnail"] = currentProfile.getThumb(); + } + } + + result = profileVariant; + + return OK; +} + +JSONRPC_STATUS CProfilesOperations::LoadProfile(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) +{ + CStdString profilename = parameterObject["profile"].asString(); + int index = CProfilesManager::Get().GetProfileIndex(profilename); + + if (index < 0) + return InvalidParams; + + // Init prompt + bool bPrompt = false; + bPrompt = parameterObject["prompt"].asBoolean(); + + bool bCanceled; + bool bLoadProfile(false); + + if (CProfilesManager::Get().GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE || // Password not needed + (bPrompt && g_passwordManager.IsProfileLockUnlocked(index, bCanceled, bPrompt))) // Password needed and user asked to enter it + bLoadProfile = true; + else if (!bCanceled && parameterObject.isMember("password")) // Password needed and user provided it + { + const CVariant &passwordObject = parameterObject["password"]; + CStdString strToVerify; // Holds user saved password hash + if (index == 0) + strToVerify = CProfilesManager::Get().GetMasterProfile().getLockCode(); + else + { + CProfile *profile = CProfilesManager::Get().GetProfile(index); + strToVerify = profile->getLockCode(); + } + + CStdString password = passwordObject["value"].asString(); + + // Create password hash from the provided password if md5 is not used + CStdString md5pword2; + CStdString encryption = passwordObject["encryption"].asString(); + if (encryption.Equals("none")) + { + XBMC::XBMC_MD5 md5state; + md5state.append(password); + md5state.getDigest(md5pword2); + } + else if (encryption.Equals("md5")) + md5pword2 = password; + + // Verify profided password + if (strToVerify.Equals(md5pword2)) + bLoadProfile = true; + } + + if (bLoadProfile) + { + CApplicationMessenger::Get().LoadProfile(index); + return ACK; + } + return InvalidParams; +} diff --git a/xbmc/interfaces/json-rpc/ProfilesOperations.h b/xbmc/interfaces/json-rpc/ProfilesOperations.h new file mode 100644 index 0000000000..360a7472fa --- /dev/null +++ b/xbmc/interfaces/json-rpc/ProfilesOperations.h @@ -0,0 +1,35 @@ +#pragma once +/* + * Copyright (C) 2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "utils/StdString.h" +#include "JSONRPC.h" +#include "FileItemHandler.h" + +namespace JSONRPC +{ + class CProfilesOperations : CFileItemHandler + { + public: + static JSONRPC_STATUS GetProfiles(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); + static JSONRPC_STATUS GetCurrentProfile(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); + static JSONRPC_STATUS LoadProfile(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); + }; +} diff --git a/xbmc/interfaces/json-rpc/ServiceDescription.h b/xbmc/interfaces/json-rpc/ServiceDescription.h index 499902e895..7f5591dd3c 100644 --- a/xbmc/interfaces/json-rpc/ServiceDescription.h +++ b/xbmc/interfaces/json-rpc/ServiceDescription.h @@ -22,7 +22,7 @@ namespace JSONRPC { const char* const JSONRPC_SERVICE_ID = "http://www.xbmc.org/jsonrpc/ServiceDescription.json"; - const char* const JSONRPC_SERVICE_VERSION = "6.5.3"; + const char* const JSONRPC_SERVICE_VERSION = "6.6.0"; const char* const JSONRPC_SERVICE_DESCRIPTION = "JSON-RPC API of XBMC"; const char* const JSONRPC_SERVICE_TYPES[] = { @@ -807,7 +807,25 @@ namespace JSONRPC "}" "}" "}", - "\"List.Filter.Rule\": {" + "\"Profiles.Password\": {" + "\"type\": \"object\"," + "\"properties\": {" + "\"value\": { \"type\": \"string\", \"required\": true, \"description\": \"Password\" }," + "\"encryption\": { \"type\": \"string\", \"description\": \"Password Encryption\", \"default\": \"md5\", \"enum\": [ \"none\", \"md5\" ] }" + "}" + "}", + "\"Profiles.Fields.Profile\": {" + "\"extends\": \"Item.Fields.Base\"," + "\"items\": { \"type\": \"string\", \"enum\": [ \"thumbnail\", \"lockmode\" ] }" + "}", + "\"Profiles.Details.Profile\": {" + "\"extends\": \"Item.Details.Base\"," + "\"properties\": {" + "\"thumbnail\": { \"type\": \"string\" }," + "\"lockmode\": { \"type\": \"integer\" }" + "}" + "}", + "\"List.Filter.Rule\": {" "\"type\": \"object\"," "\"properties\": {" "\"operator\": { \"$ref\": \"List.Filter.Operators\", \"required\": true }," @@ -2934,6 +2952,48 @@ namespace JSONRPC "\"params\": [ ]," "\"returns\": \"string\"" "}", + "\"Profiles.GetProfiles\": {" + "\"type\": \"method\"," + "\"description\": \"Retrieve all profiles\"," + "\"transport\": \"Response\"," + "\"permission\": \"ReadData\"," + "\"params\": [" + "{ \"name\": \"properties\", \"$ref\": \"Profiles.Fields.Profile\" }," + "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" }," + "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }" + "]," + "\"returns\": {" + "\"type\": \"object\"," + "\"properties\": {" + "\"limits\": { \"$ref\": \"List.LimitsReturned\", \"required\": true }," + "\"profiles\": { \"type\": \"array\", \"required\": true," + "\"items\": { \"$ref\": \"Profiles.Details.Profile\" }" + "}" + "}" + "}" + "}", + "\"Profiles.GetCurrentProfile\": {" + "\"type\": \"method\"," + "\"description\": \"Retrieve the current profile\"," + "\"transport\": \"Response\"," + "\"permission\": \"ReadData\"," + "\"params\": [" + "{ \"name\": \"properties\", \"$ref\": \"Profiles.Fields.Profile\" }" + "]," + "\"returns\": { \"$ref\": \"Profiles.Details.Profile\", \"required\": true }" + "}", + "\"Profiles.LoadProfile\": {" + "\"type\": \"method\"," + "\"description\": \"Load the specified profile\"," + "\"transport\": \"Response\"," + "\"permission\": \"Navigate\"," + "\"params\": [" + "{ \"name\": \"profile\", \"type\": \"string\", \"required\": true, \"description\": \"Profile name\" }," + "{ \"name\": \"prompt\", \"type\": \"boolean\", \"description\": \"Prompt for password\" }," + "{ \"name\": \"password\", \"$ref\": \"Profiles.Password\" }" + "]," + "\"returns\": \"string\"" + "}", "\"System.GetProperties\": {" "\"type\": \"method\"," "\"description\": \"Retrieves the values of the given properties\"," diff --git a/xbmc/interfaces/json-rpc/methods.json b/xbmc/interfaces/json-rpc/methods.json index f8a551cf5a..627c32a775 100644 --- a/xbmc/interfaces/json-rpc/methods.json +++ b/xbmc/interfaces/json-rpc/methods.json @@ -1664,6 +1664,48 @@ "params": [ ], "returns": "string" }, + "Profiles.GetProfiles": { + "type": "method", + "description": "Retrieve all profiles", + "transport": "Response", + "permission": "ReadData", + "params": [ + { "name": "properties", "$ref": "Profiles.Fields.Profile" }, + { "name": "limits", "$ref": "List.Limits" }, + { "name": "sort", "$ref": "List.Sort" }" + ], + "returns": { + "type": "object", + "properties": { + "limits": { "$ref": "List.LimitsReturned", "required": true }, + "profiles": { "type": "array", "required": true, + "items": { "$ref": "Profiles.Details.Profile" } + } + } + } + }, + "Profiles.GetCurrentProfile": { + "type": "method", + "description": "Retrieve the current profile", + "transport": "Response", + "permission": "ReadData", + "params": [ + { "name": "properties", "$ref": "Profiles.Fields.Profile" } + ], + "returns": { "$ref": "Profiles.Details.Profile", "required": true } + }, + "Profiles.LoadProfile": { + "type": "method", + "description": "Load the specified profile", + "transport": "Response", + "permission": "Navigate", + "params": [ + { "name": "profile", "type": "string", "required": true, "description": "Profile name" }, + { "name": "prompt", "type": "boolean", "description": "Prompt for password" }, + { "name": "password", "$ref": "Profiles.Password" } + ], + "returns": "string" + }, "System.GetProperties": { "type": "method", "description": "Retrieves the values of the given properties", diff --git a/xbmc/interfaces/json-rpc/types.json b/xbmc/interfaces/json-rpc/types.json index 2c6d622144..3e30b09c7b 100644 --- a/xbmc/interfaces/json-rpc/types.json +++ b/xbmc/interfaces/json-rpc/types.json @@ -780,6 +780,24 @@ } } }, + "Profiles.Password": { + "type": "object", + "properties": { + "value": { "type": "string", "required": true, "description": "Password" }, + "encryption": { "type": "string", "description": "Password Encryption", "default": "md5", "enum": [ "none", "md5" ] } + } + }, + "Profiles.Fields.Profile": { + "extends": "Item.Fields.Base", + "items": { "type": "string", "enum": [ "thumbnail", "lockmode" ] } + }, + "Profiles.Details.Profile": { + "extends": "Item.Details.Base", + "properties": { + "thumbnail": { "type": "string" }, + "lockmode": { "type": "integer" } + } + }, "List.Filter.Rule": { "type": "object", "properties": { |