diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-01 23:09:56 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-01 23:41:20 +0200 |
commit | 633f7007d1e9cf6492560ed4e644f6c4d92747f8 (patch) | |
tree | 8a87c3d3f715b584855a16de3d19fa8c980e5547 | |
parent | f4d178b3f6f917b8ff19234498e824277b5163e3 (diff) | |
download | json-rpc-shell-633f7007d1e9cf6492560ed4e644f6c4d92747f8.tar.gz json-rpc-shell-633f7007d1e9cf6492560ed4e644f6c4d92747f8.tar.xz json-rpc-shell-633f7007d1e9cf6492560ed4e644f6c4d92747f8.zip |
json-rpc-test-server: add a "date" method
-rw-r--r-- | json-rpc-test-server.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/json-rpc-test-server.c b/json-rpc-test-server.c index 951a4c6..2031034 100644 --- a/json-rpc-test-server.c +++ b/json-rpc-test-server.c @@ -1458,12 +1458,35 @@ json_rpc_ping (struct server_context *ctx, json_t *params) } static json_t * +json_rpc_date (struct server_context *ctx, json_t *params) +{ + (void) ctx; + + if (params && !json_is_null (params)) + return json_rpc_response (NULL, NULL, + json_rpc_error (JSON_RPC_ERROR_INVALID_PARAMS, NULL)); + + time_t now = time (NULL); + const struct tm *tm = localtime (&now); + json_t *x = json_object (); + + json_object_set_new (x, "year", json_integer (tm->tm_year + 1900)); + json_object_set_new (x, "month", json_integer (tm->tm_mon + 1)); + json_object_set_new (x, "day", json_integer (tm->tm_mday)); + json_object_set_new (x, "hours", json_integer (tm->tm_hour)); + json_object_set_new (x, "minutes", json_integer (tm->tm_min)); + json_object_set_new (x, "seconds", json_integer (tm->tm_sec)); + return json_rpc_response (NULL, x, NULL); +} + +static json_t * process_json_rpc_request (struct server_context *ctx, json_t *request) { // A list of all available methods; this list has to be ordered. // 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 }, }; |