Browse Source

MT#61630 support CLI commands via POST

Change-Id: I2970b331f4889bed7eab11d33ab16751ef4246a5
pull/1907/head
Richard Fuchs 11 months ago
parent
commit
17c7fd5375
3 changed files with 28 additions and 5 deletions
  1. +20
    -0
      daemon/websocket.c
  2. +7
    -5
      docs/http_websocket_support.md
  3. +1
    -0
      include/websocket.h

+ 20
- 0
daemon/websocket.c View File

@ -457,6 +457,22 @@ static const char *websocket_http_cli(struct websocket_message *wm) {
}
static const char *websocket_http_cli_post(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Respoding to POST /cli");
struct cli_writer cw = {
.cw_printf = websocket_queue_printf,
.ptr = wm->wc,
};
cli_handle(&STR_LEN(wm->body->str, wm->body->len), &cw);
size_t len = websocket_queue_len(wm->wc);
websocket_http_complete(wm->wc, 200, "text/plain", len, NULL);
return NULL;
}
static const char *websocket_cli_process(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Processing websocket CLI req '%s'", wm->body->str);
@ -622,6 +638,8 @@ static int websocket_http_post(struct websocket_conn *wc) {
wm->content_type = CT_JSON;
else if (!strcasecmp(ct, "application/x-rtpengine-ng"))
wm->content_type = CT_NG;
else if (!strcasecmp(ct, "text/plain"))
wm->content_type = CT_TEXT;
else
ilogs(http, LOG_WARN, "Unsupported content-type '%s'", ct);
@ -677,6 +695,8 @@ static int websocket_http_body(struct websocket_conn *wc, const char *body, size
handler = websocket_janus_process;
else if (!strncmp(uri, "/janus/", 7) && wm->method == M_POST && wm->content_type == CT_JSON)
handler = websocket_janus_post;
else if (!strcmp(uri, "/cli") && wm->method == M_POST && wm->content_type == CT_TEXT)
handler = websocket_http_cli_post;
else
handler = websocket_http_404;


+ 7
- 5
docs/http_websocket_support.md View File

@ -16,11 +16,13 @@ are sent to it.
This interface supports the same commands as the CLI tool `rtpengine-ctl` that
comes packaged with `rtpengine`. For HTTP and HTTPS, the command is appended to
the URI base `/cli/` and the request is made via `GET`, with spaces replaced by
plus signs as required by HTTP (e.g. `GET /cli/list+totals`). For WebSockets,
the subprotocol is `cli.rtpengine.com` and each WebSocket message corresponds
to one CLI command and produces one message in response. The format of each
response is exactly the same as produced by the CLI tool `rtpengine-ctl` and
therefore meant for plain text representation.
plus signs as required by HTTP (e.g. `GET /cli/list+totals`), or alternatively,
the command is sent as request body if the request is made via `POST`, using a
content-type of `text/plain`. For WebSockets, the subprotocol is
`cli.rtpengine.com` and each WebSocket message corresponds to one CLI command
and produces one message in response. The format of each response is exactly
the same as produced by the CLI tool `rtpengine-ctl` and therefore meant for
plain text representation.
## *ng* Protocol Interface


+ 1
- 0
include/websocket.h View File

@ -27,6 +27,7 @@ struct websocket_message {
CT_UNKNOWN = 0,
CT_JSON,
CT_NG,
CT_TEXT,
} content_type;
GString *body;


Loading…
Cancel
Save