From: AsamK Date: Wed, 2 Nov 2022 16:46:20 +0000 (+0100) Subject: Update man page X-Git-Tag: v0.11.5~13 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/c628e27d2e1372c4ed9bc4ee319b83700cd11b17 Update man page --- diff --git a/man/signal-cli-dbus.5.adoc b/man/signal-cli-dbus.5.adoc index bc3ad40d..1d78f7f6 100644 --- a/man/signal-cli-dbus.5.adoc +++ b/man/signal-cli-dbus.5.adoc @@ -5,6 +5,7 @@ vim:set ts=4 sw=4 tw=82 noet: :quotes.~: = signal-cli-dbus (5) +:doctype: manpage == Name diff --git a/man/signal-cli-jsonrpc.5.adoc b/man/signal-cli-jsonrpc.5.adoc index f0b62ca9..ff709f31 100644 --- a/man/signal-cli-jsonrpc.5.adoc +++ b/man/signal-cli-jsonrpc.5.adoc @@ -5,6 +5,7 @@ vim:set ts=4 sw=4 tw=82 noet: :quotes.~: = signal-cli-jsonrpc (5) +:doctype: manpage == Name diff --git a/man/signal-cli.1.adoc b/man/signal-cli.1.adoc index d55d8ec7..ad510dfe 100644 --- a/man/signal-cli.1.adoc +++ b/man/signal-cli.1.adoc @@ -5,6 +5,7 @@ vim:set ts=4 sw=4 tw=82 noet: :quotes.~: = signal-cli (1) +:doctype: manpage == Name @@ -601,7 +602,7 @@ The primary device will respond with synchronization messages with full contact === uploadStickerPack -Upload a new sticker pack, consisting of a manifest file and the sticker images. +Upload a new sticker pack, consisting of a manifest file and the sticker images. + Images must conform to the following specification: (see https://support.signal.org/hc/en-us/articles/360031836512-Stickers#sticker_reqs ) - Static stickers in PNG or WebP format @@ -657,20 +658,25 @@ signal-cli can run in daemon mode and provides an experimental dbus or JSON-RPC If no `-a` account is given, all local accounts will be exported as separate dbus objects under the same bus name. *--dbus*:: -Export DBus interface on user bus. -See signal-cli-dbus (5) for info on the dbus interface. +Export DBus interface on user bus. + +See **signal-cli-dbus**(5) for info on the dbus interface. *--dbus-system*:: -Export DBus interface on system bus. -See signal-cli-dbus (5) for info on the dbus interface. +Export DBus interface on system bus. + +See **signal-cli-dbus**(5) for info on the dbus interface. *--socket [SOCKET]*:: -Export a JSON-RPC interface on a UNIX socket (default $XDG_RUNTIME_DIR/signal-cli/socket). -See signal-cli-jsonrpc (5) for info on the JSON-RPC interface. +Export a JSON-RPC interface on a UNIX socket (default $XDG_RUNTIME_DIR/signal-cli/socket). + +See **signal-cli-jsonrpc**(5) for info on the JSON-RPC interface. *--tcp [HOST:PORT]*:: -Export a JSON-RPC interface on a TCP socket (default localhost:7583). -See signal-cli-jsonrpc (5) for info on the JSON-RPC interface. +Export a JSON-RPC interface on a TCP socket (default localhost:7583). + +See **signal-cli-jsonrpc**(5) for info on the JSON-RPC interface. + +*--http [HOST:PORT]*:: +Expose a JSON-RPC interface as http endpoint (default localhost:8080). +The JSON-RPC endpoint is `/api/v1/rpc`. + +See **signal-cli-jsonrpc**(5) for info on the JSON-RPC interface. *--ignore-attachments*:: Don’t download attachments of received messages. diff --git a/src/main/java/org/asamk/signal/commands/DaemonCommand.java b/src/main/java/org/asamk/signal/commands/DaemonCommand.java index bd6b9386..0cdf9cc9 100644 --- a/src/main/java/org/asamk/signal/commands/DaemonCommand.java +++ b/src/main/java/org/asamk/signal/commands/DaemonCommand.java @@ -73,7 +73,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand { subparser.addArgument("--http") .nargs("?") .setConst("localhost:8080") - .help("Expose a JSON-RPC interface as http endpoint."); + .help("Expose a JSON-RPC interface as http endpoint (default localhost:8080)."); subparser.addArgument("--no-receive-stdout") .help("Don’t print received messages to stdout.") .action(Arguments.storeTrue()); diff --git a/src/main/java/org/asamk/signal/http/HttpServerHandler.java b/src/main/java/org/asamk/signal/http/HttpServerHandler.java index b2544b25..9fb33a34 100644 --- a/src/main/java/org/asamk/signal/http/HttpServerHandler.java +++ b/src/main/java/org/asamk/signal/http/HttpServerHandler.java @@ -41,54 +41,56 @@ public class HttpServerHandler { public void init() throws IOException { - logger.info("Starting server on " + address.toString()); + logger.info("Starting server on " + address.toString()); - final var server = HttpServer.create(address, 0); - server.setExecutor(Executors.newFixedThreadPool(10)); + final var server = HttpServer.create(address, 0); + server.setExecutor(Executors.newFixedThreadPool(10)); - server.createContext("/api/v1/rpc", httpExchange -> { + server.createContext("/api/v1/rpc", httpExchange -> { - if (!"POST".equals(httpExchange.getRequestMethod())) { - sendResponse(405, null, httpExchange); - return; - } - - if (!"application/json".equals(httpExchange.getRequestHeaders().getFirst("Content-Type"))) { - sendResponse(415, null, httpExchange); - return; - } + if (!"POST".equals(httpExchange.getRequestMethod())) { + sendResponse(405, null, httpExchange); + return; + } - try { + if (!"application/json".equals(httpExchange.getRequestHeaders().getFirst("Content-Type"))) { + sendResponse(415, null, httpExchange); + return; + } - final Object[] result = {null}; - final var jsonRpcSender = new JsonRpcSender(s -> { - if (result[0] != null) { - throw new AssertionError("There should only be a single JSON-RPC response"); - } + try { - result[0] = s; - }); + final Object[] result = {null}; + final var jsonRpcSender = new JsonRpcSender(s -> { + if (result[0] != null) { + throw new AssertionError("There should only be a single JSON-RPC response"); + } - final var jsonRpcReader = new JsonRpcReader(jsonRpcSender, httpExchange.getRequestBody()); - jsonRpcReader.readMessages((method, params) -> commandHandler.handleRequest(objectMapper, method, params), - response -> logger.debug("Received unexpected response for id {}", response.getId())); + result[0] = s; + }); - if (result[0] !=null) { - sendResponse(200, result[0], httpExchange); - } else { - sendResponse(201, null, httpExchange); - } + final var jsonRpcReader = new JsonRpcReader(jsonRpcSender, httpExchange.getRequestBody()); + jsonRpcReader.readMessages((method, params) -> commandHandler.handleRequest(objectMapper, + method, + params), response -> logger.debug("Received unexpected response for id {}", response.getId())); + if (result[0] != null) { + sendResponse(200, result[0], httpExchange); + } else { + sendResponse(201, null, httpExchange); } - catch (Throwable aEx) { - logger.error("Failed to process request.", aEx); - sendResponse(200, JsonRpcResponse.forError( - new JsonRpcResponse.Error(JsonRpcResponse.Error.INTERNAL_ERROR, - "An internal server error has occurred.", null), null), httpExchange); - } - }); - server.start(); + } catch (Throwable aEx) { + logger.error("Failed to process request.", aEx); + sendResponse(200, + JsonRpcResponse.forError(new JsonRpcResponse.Error(JsonRpcResponse.Error.INTERNAL_ERROR, + "An internal server error has occurred.", + null), null), + httpExchange); + } + }); + + server.start(); }