aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-13 20:23:05 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-13 20:54:27 +0200
commitd489362a28395f47baff248fdd4170acb79c4cdb (patch)
tree80d9caea0855c83cc132a6c098baebd1031e670f
parentc87869bef7553199a874a7af304d2a4b13f0f689 (diff)
downloadjson-rpc-shell-d489362a28395f47baff248fdd4170acb79c4cdb.tar.gz
json-rpc-shell-d489362a28395f47baff248fdd4170acb79c4cdb.tar.xz
json-rpc-shell-d489362a28395f47baff248fdd4170acb79c4cdb.zip
json-rpc-test-server: implement rpc.discover
-rw-r--r--json-rpc-test-server.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/json-rpc-test-server.c b/json-rpc-test-server.c
index 36256d4..d849b83 100644
--- a/json-rpc-test-server.c
+++ b/json-rpc-test-server.c
@@ -1447,6 +1447,38 @@ json_rpc_handler_info_cmp (const void *first, const void *second)
}
static json_t *
+open_rpc_describe (const char *method, json_t *result)
+{
+ return json_pack ("{sssoso}", "name", method, "params", json_pack ("[]"),
+ "result", json_pack ("{ssso}", "name", method, "schema", result));
+}
+
+// This server rarely sees changes and we can afford to hardcode the schema
+static json_t *
+json_rpc_discover (struct server_context *ctx, json_t *params)
+{
+ (void) ctx;
+ (void) params;
+
+ json_t *info = json_pack ("{ssss}",
+ "title", PROGRAM_NAME, "version", PROGRAM_VERSION);
+ json_t *methods = json_pack ("[ooo]",
+ open_rpc_describe ("date", json_pack ("{ssso}", "type", "object",
+ "properties", json_pack ("{s{ss}s{ss}s{ss}s{ss}s{ss}s{ss}}",
+ "year", "type", "number",
+ "month", "type", "number",
+ "day", "type", "number",
+ "hours", "type", "number",
+ "minutes", "type", "number",
+ "seconds", "type", "number"))),
+ open_rpc_describe ("ping", json_pack ("{ss}", "type", "string")),
+ open_rpc_describe ("rpc.discover", json_pack ("{ss}", "$ref",
+ "https://github.com/open-rpc/meta-schema/raw/master/schema.json")));
+ return json_rpc_response (NULL, json_pack ("{sssoso}",
+ "openrpc", "1.2.6", "info", info, "methods", methods), NULL);
+}
+
+static json_t *
json_rpc_ping (struct server_context *ctx, json_t *params)
{
(void) ctx;
@@ -1487,8 +1519,9 @@ process_json_rpc_request (struct server_context *ctx, json_t *request)
// Eventually it might be better to move this into a map in the context.
static struct json_rpc_handler_info handlers[] =
{
- { "date", json_rpc_date },
- { "ping", json_rpc_ping },
+ { "date", json_rpc_date },
+ { "ping", json_rpc_ping },
+ { "rpc.discover", json_rpc_discover },
};
if (!json_is_object (request))