1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "JSONRPCUtils.h"
#include "JSONServiceDescription.h"
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
class CVariant;
namespace JSONRPC
{
/*!
\ingroup jsonrpc
\brief JSON RPC handler
Sets up and manages all needed information to process
JSON-RPC requests and answering with the appropriate
JSON-RPC response (actual response or error message).
*/
class CJSONRPC
{
public:
/*!
\brief Initializes the JSON-RPC handler
*/
static void Initialize();
static void Cleanup();
/*
\brief Handles an incoming JSON-RPC request
\param inputString received JSON-RPC request
\param transport Transport protocol on which the request arrived
\param client Client which sent the request
\return JSON-RPC response to be sent back to the client
Parses the received input string for the called method and provided
parameters. If the request does not conform to the JSON-RPC 2.0
specification an error is returned. Otherwise the parameters provided
in the request are checked for validity and completeness. If the request
is valid and the requested method exists it is called and executed.
*/
static std::string MethodCall(const std::string &inputString, ITransportLayer *transport, IClient *client);
static JSONRPC_STATUS Introspect(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS Version(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS Permission(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS Ping(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS GetConfiguration(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS SetConfiguration(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
static JSONRPC_STATUS NotifyAll(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
private:
static bool HandleMethodCall(const CVariant& request, CVariant& response, ITransportLayer *transport, IClient *client);
static inline bool IsProperJSONRPC(const CVariant& inputroot);
inline static void BuildResponse(const CVariant& request, JSONRPC_STATUS code, const CVariant& result, CVariant& response);
static bool m_initialized;
};
}
|