MT#61630 support CLI commands via POST

Change-Id: I2970b331f4889bed7eab11d33ab16751ef4246a5
pull/1907/head
Richard Fuchs 1 year ago
parent 3e0bd2e76f
commit 17c7fd5375

@ -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) { static const char *websocket_cli_process(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Processing websocket CLI req '%s'", wm->body->str); 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; wm->content_type = CT_JSON;
else if (!strcasecmp(ct, "application/x-rtpengine-ng")) else if (!strcasecmp(ct, "application/x-rtpengine-ng"))
wm->content_type = CT_NG; wm->content_type = CT_NG;
else if (!strcasecmp(ct, "text/plain"))
wm->content_type = CT_TEXT;
else else
ilogs(http, LOG_WARN, "Unsupported content-type '%s'", ct); 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; handler = websocket_janus_process;
else if (!strncmp(uri, "/janus/", 7) && wm->method == M_POST && wm->content_type == CT_JSON) else if (!strncmp(uri, "/janus/", 7) && wm->method == M_POST && wm->content_type == CT_JSON)
handler = websocket_janus_post; handler = websocket_janus_post;
else if (!strcmp(uri, "/cli") && wm->method == M_POST && wm->content_type == CT_TEXT)
handler = websocket_http_cli_post;
else else
handler = websocket_http_404; handler = websocket_http_404;

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

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

Loading…
Cancel
Save