Asterisk - The Open Source Telephony Project GIT-master-8b8a8c1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Macros | Functions | Variables
res/ari/cli.c File Reference

Command line for ARI. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "asterisk/stasis_app.h"
#include "asterisk/uuid.h"
#include "internal.h"
#include "ari_websockets.h"
Include dependency graph for res/ari/cli.c:

Go to the source code of this file.

Macros

#define DASHES   "----------------------------------------------------------------------"
 
#define DASHES   "----------------------------------------------------------------------"
 

Functions

int ari_cli_register (void)
 Register CLI commands for ARI. More...
 
void ari_cli_unregister (void)
 Unregister CLI commands for ARI. More...
 
static char * ari_mkpasswd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_app (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_apps (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_owc (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_owcs (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_sessions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_user (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_show_users (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_shut_session (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_shut_sessions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * ari_start_owc (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void complete_app (struct ao2_container *container, const char *word)
 
static void complete_session (struct ao2_container *container, const char *word)
 
static void complete_sorcery_object (struct ao2_container *container, const char *word)
 
static int show_owc_cb (void *obj, void *arg, int flags)
 
static int show_sessions_cb (void *obj, void *arg, int flags)
 
static int show_users_cb (void *obj, void *arg, int flags)
 

Variables

static struct ast_cli_entry cli_ari []
 

Detailed Description

Command line for ARI.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file res/ari/cli.c.

Macro Definition Documentation

◆ DASHES [1/2]

#define DASHES   "----------------------------------------------------------------------"

Definition at line 555 of file res/ari/cli.c.

◆ DASHES [2/2]

#define DASHES   "----------------------------------------------------------------------"

Definition at line 555 of file res/ari/cli.c.

Function Documentation

◆ ari_cli_register()

int ari_cli_register ( void  )

Register CLI commands for ARI.

Returns
0 on success.
Non-zero on error.

Definition at line 699 of file res/ari/cli.c.

699 {
701}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_ari[]
Definition: res/ari/cli.c:683
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, and cli_ari.

Referenced by load_module().

◆ ari_cli_unregister()

void ari_cli_unregister ( void  )

Unregister CLI commands for ARI.

Definition at line 703 of file res/ari/cli.c.

703 {
705}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), and cli_ari.

Referenced by unload_module().

◆ ari_mkpasswd()

static char * ari_mkpasswd ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 180 of file res/ari/cli.c.

181{
182 RAII_VAR(char *, crypted, NULL, ast_free);
183
184 switch (cmd) {
185 case CLI_INIT:
186 e->command = "ari mkpasswd";
187 e->usage =
188 "Usage: ari mkpasswd <password>\n"
189 " Encrypts a password for use in ari.conf\n"
190 " Be aware that the password will be shown in the\n"
191 " command line history. The mkpasswd shell command\n"
192 " may be preferable.\n"
193 ;
194 return NULL;
195 case CLI_GENERATE:
196 return NULL;
197 default:
198 break;
199 }
200
201 if (a->argc != 3) {
202 return CLI_SHOWUSAGE;
203 }
204
205 crypted = ast_crypt_encrypt(a->argv[2]);
206 if (!crypted) {
207 ast_cli(a->fd, "Failed to encrypt password\n");
208 return CLI_FAILURE;
209 }
210
211 ast_cli(a->fd,
212 "; Copy the following two lines into ari.conf\n");
213 ast_cli(a->fd, "password_format = crypt\n");
214 ast_cli(a->fd, "password = %s\n", crypted);
215
216 return CLI_SUCCESS;
217}
#define ast_free(a)
Definition: astmm.h:180
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define CLI_FAILURE
Definition: cli.h:46
#define NULL
Definition: resample.c:96
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
static struct test_val a
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
char * ast_crypt_encrypt(const char *key)
Asterisk wrapper around crypt(3) for encrypting passwords.
Definition: crypt.c:190

References a, ast_cli(), ast_crypt_encrypt(), ast_free, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, RAII_VAR, and ast_cli_entry::usage.

◆ ari_set_debug()

static char * ari_set_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 320 of file res/ari/cli.c.

321{
323 void *app;
324 int debug;
325
326 if (!apps) {
327 ast_cli(a->fd, "Error getting ARI applications\n");
328 return CLI_FAILURE;
329 }
330
331 switch (cmd) {
332 case CLI_INIT:
333 e->command = "ari set debug";
334 e->usage =
335 "Usage: ari set debug <application|all> <on|off>\n"
336 " Enable or disable debugging on a specific application.\n"
337 ;
338 return NULL;
339 case CLI_GENERATE:
340 if (a->argc == 3) {
342 complete_app(apps, a->word);
343 } else if (a->argc == 4) {
346 }
347 return NULL;
348 default:
349 break;
350 }
351
352 if (a->argc != 5) {
353 return CLI_SHOWUSAGE;
354 }
355
356 debug = !strcmp(a->argv[4], "on");
357
358 if (!strcmp(a->argv[3], "all")) {
360 ast_cli(a->fd, "Debugging on all applications %s\n",
361 debug ? "enabled" : "disabled");
362 return CLI_SUCCESS;
363 }
364
365 app = stasis_app_get_by_name(a->argv[3]);
366 if (!app) {
367 return CLI_FAILURE;
368 }
369
371 ast_cli(a->fd, "Debugging on '%s' %s\n",
373 debug ? "enabled" : "disabled");
374
375 ao2_ref(app, -1);
376
377 return CLI_SUCCESS;
378}
static const char app[]
Definition: app_adsiprog.c:56
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2768
static void complete_app(struct ao2_container *container, const char *word)
Definition: res/ari/cli.c:263
static int debug
Global debug status.
Definition: res_xmpp.c:570
void stasis_app_set_debug(struct stasis_app *app, int debug)
Enable/disable request/response and event logging on an application.
void stasis_app_set_global_debug(int debug)
Enable/disable request/response and event logging on all applications.
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1742
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
Definition: res_stasis.c:1769
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.
Generic container type.
Registered applications container.
Definition: pbx_app.c:68

References a, ao2_cleanup, ao2_ref, app, ast_cli(), ast_cli_completion_add(), ast_strdup, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_app(), debug, NULL, RAII_VAR, stasis_app_get_all(), stasis_app_get_by_name(), stasis_app_name(), stasis_app_set_debug(), stasis_app_set_global_debug(), and ast_cli_entry::usage.

◆ ari_show()

static char * ari_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 34 of file res/ari/cli.c.

35{
36 RAII_VAR(struct ari_conf_general *, general, NULL, ao2_cleanup);
37
38 switch (cmd) {
39 case CLI_INIT:
40 e->command = "ari show status";
41 e->usage =
42 "Usage: ari show status\n"
43 " Shows all ARI settings\n";
44 return NULL;
45 case CLI_GENERATE:
46 return NULL;
47 default:
48 break;
49 }
50
51 if (a->argc != 3) {
52 return CLI_SHOWUSAGE;
53 }
54
55 general = ari_conf_get_general();
56
57 if (!general) {
58 ast_cli(a->fd, "Error getting ARI configuration\n");
59 return CLI_FAILURE;
60 }
61
62 ast_cli(a->fd, "ARI Status:\n");
63 ast_cli(a->fd, "Enabled: %s\n", AST_CLI_YESNO(general->enabled));
64 ast_cli(a->fd, "Output format: ");
65 if (general->format & AST_JSON_PRETTY) {
66 ast_cli(a->fd, "pretty");
67 } else {
68 ast_cli(a->fd, "compact");
69 }
70 ast_cli(a->fd, "\n");
71 ast_cli(a->fd, "Auth realm: %s\n", general->auth_realm);
72 ast_cli(a->fd, "Allowed Origins: %s\n", general->allowed_origins);
73 return CLI_SUCCESS;
74}
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
Definition: cli.h:71
@ AST_JSON_PRETTY
Definition: json.h:795
struct ari_conf_general * ari_conf_get_general(void)
Global configuration options for ARI.
Definition: internal.h:57

References a, ao2_cleanup, ari_conf_get_general(), ast_cli(), AST_CLI_YESNO, AST_JSON_PRETTY, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, RAII_VAR, and ast_cli_entry::usage.

◆ ari_show_app()

static char * ari_show_app ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 279 of file res/ari/cli.c.

280{
281 void *app;
283
284 if (!apps) {
285 ast_cli(a->fd, "Error getting ARI applications\n");
286 return CLI_FAILURE;
287 }
288
289 switch (cmd) {
290 case CLI_INIT:
291 e->command = "ari show app";
292 e->usage =
293 "Usage: ari show app <application>\n"
294 " Provide detailed information about a registered application.\n"
295 ;
296 return NULL;
297 case CLI_GENERATE:
298 complete_app(apps, a->word);
299 return NULL;
300 default:
301 break;
302 }
303
304 if (a->argc != 4) {
305 return CLI_SHOWUSAGE;
306 }
307
308 app = stasis_app_get_by_name(a->argv[3]);
309 if (!app) {
310 return CLI_FAILURE;
311 }
312
314
315 ao2_ref(app, -1);
316
317 return CLI_SUCCESS;
318}
void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a)
Dump properties of a stasis_app to the CLI.

References a, ao2_cleanup, ao2_ref, app, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_app(), NULL, RAII_VAR, stasis_app_get_all(), stasis_app_get_by_name(), stasis_app_to_cli(), and ast_cli_entry::usage.

◆ ari_show_apps()

static char * ari_show_apps ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 219 of file res/ari/cli.c.

220{
221 struct ao2_container *apps;
222 struct ao2_iterator it_apps;
223 char *app;
224
225 switch (cmd) {
226 case CLI_INIT:
227 e->command = "ari show apps";
228 e->usage =
229 "Usage: ari show apps\n"
230 " Lists all registered applications.\n"
231 ;
232 return NULL;
233 case CLI_GENERATE:
234 return NULL;
235 default:
236 break;
237 }
238
239 if (a->argc != 3) {
240 return CLI_SHOWUSAGE;
241 }
242
244 if (!apps) {
245 ast_cli(a->fd, "Unable to retrieve registered applications!\n");
246 return CLI_FAILURE;
247 }
248
249 ast_cli(a->fd, "Application Name \n");
250 ast_cli(a->fd, "=========================\n");
251 it_apps = ao2_iterator_init(apps, 0);
252 while ((app = ao2_iterator_next(&it_apps))) {
253 ast_cli(a->fd, "%s\n", app);
254 ao2_ref(app, -1);
255 }
256
257 ao2_iterator_destroy(&it_apps);
258 ao2_ref(apps, -1);
259
260 return CLI_SUCCESS;
261}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static struct apps apps
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References a, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, app, apps, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, stasis_app_get_all(), and ast_cli_entry::usage.

◆ ari_show_owc()

static char * ari_show_owc ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 433 of file res/ari/cli.c.

434{
437 const char *id = NULL;
438 enum ari_conf_owc_fields invalid_fields;
439
440 switch (cmd) {
441 case CLI_INIT:
442 e->command = "ari show outbound-websocket";
443 e->usage =
444 "Usage: ari show outbound-websocket <connection id>\n"
445 " Shows a specific ARI outbound websocket\n";
446 return NULL;
447 case CLI_GENERATE:
448 complete_sorcery_object(owcs, a->word);
449 return NULL;
450 default:
451 break;
452 }
453
454 if (a->argc != 4) {
455 return CLI_SHOWUSAGE;
456 }
457
458 owc = ari_conf_get_owc(a->argv[3]);
459 if (!owc) {
460 ast_cli(a->fd, "Error getting ARI configuration\n");
461 return CLI_FAILURE;
462 }
464 invalid_fields = ari_conf_owc_get_invalid_fields(id);
465
466 ast_cli(a->fd, "[%s] %s\n", id,
467 invalid_fields == ARI_OWC_FIELD_NONE ? "" : "**INVALID**");
468 ast_cli(a->fd, "uri = %s\n", owc->websocket_client->uri);
469 ast_cli(a->fd, "protocols = %s\n", owc->websocket_client->protocols);
470 ast_cli(a->fd, "apps = %s%s\n", owc->apps,
471 invalid_fields & ARI_OWC_FIELD_APPS ? " (invalid)" : "");
472 ast_cli(a->fd, "username = %s\n", owc->websocket_client->username);
473 ast_cli(a->fd, "password = %s\n", S_COR(owc->websocket_client->password, "********", ""));
474 ast_cli(a->fd, "local_ari_user = %s%s\n", owc->local_ari_user,
475 invalid_fields & ARI_OWC_FIELD_LOCAL_ARI_USER ? " (invalid)" : "");
476 ast_cli(a->fd, "connection_type = %s\n", ari_websocket_type_to_str(owc->websocket_client->connection_type));
477 ast_cli(a->fd, "subscribe_all = %s\n", AST_CLI_YESNO(owc->subscribe_all));
478 ast_cli(a->fd, "connec_timeout = %d\n", owc->websocket_client->connect_timeout);
479 ast_cli(a->fd, "reconnect_attempts = %d\n", owc->websocket_client->reconnect_attempts);
480 ast_cli(a->fd, "reconnect_interval = %d\n", owc->websocket_client->reconnect_interval);
481 ast_cli(a->fd, "tls_enabled = %s\n", AST_CLI_YESNO(owc->websocket_client->tls_enabled));
482 ast_cli(a->fd, "ca_list_file = %s\n", owc->websocket_client->ca_list_file);
483 ast_cli(a->fd, "ca_list_path = %s\n", owc->websocket_client->ca_list_path);
484 ast_cli(a->fd, "cert_file = %s\n", owc->websocket_client->cert_file);
485 ast_cli(a->fd, "priv_key_file = %s\n", owc->websocket_client->priv_key_file);
486 ast_cli(a->fd, "verify_server = %s\n", AST_CLI_YESNO(owc->websocket_client->verify_server_cert));
487 ast_cli(a->fd, "verify_server_hostname = %s\n", AST_CLI_YESNO(owc->websocket_client->verify_server_hostname));
488 ast_cli(a->fd, "\n");
489
490 return CLI_SUCCESS;
491}
const char * ari_websocket_type_to_str(enum ast_websocket_type type)
ari_conf_owc_fields
Definition: internal.h:96
@ ARI_OWC_FIELD_APPS
Definition: internal.h:99
@ ARI_OWC_FIELD_NONE
Definition: internal.h:97
@ ARI_OWC_FIELD_LOCAL_ARI_USER
Definition: internal.h:100
static void complete_sorcery_object(struct ao2_container *container, const char *word)
Definition: res/ari/cli.c:123
enum ari_conf_owc_fields ari_conf_owc_get_invalid_fields(const char *id)
struct ao2_container * ari_conf_get_owcs(void)
struct ari_conf_outbound_websocket * ari_conf_get_owc(const char *id)
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87

References a, ao2_cleanup, ari_conf_get_owc(), ari_conf_get_owcs(), ari_conf_owc_get_invalid_fields(), ARI_OWC_FIELD_APPS, ARI_OWC_FIELD_LOCAL_ARI_USER, ARI_OWC_FIELD_NONE, ari_websocket_type_to_str(), ast_cli(), AST_CLI_YESNO, ast_sorcery_object_get_id(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sorcery_object(), NULL, RAII_VAR, S_COR, and ast_cli_entry::usage.

◆ ari_show_owcs()

static char * ari_show_owcs ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 397 of file res/ari/cli.c.

399{
400 RAII_VAR(struct ao2_container *, owcs, NULL, ao2_cleanup);
401
402 switch (cmd) {
403 case CLI_INIT:
404 e->command = "ari show outbound-websockets";
405 e->usage =
406 "Usage: ari show outbound-websockets\n"
407 " Shows all ARI outbound-websockets\n";
408 return NULL;
409 case CLI_GENERATE:
410 return NULL;
411 default:
412 break;
413 }
414
415 if (a->argc != 3) {
416 return CLI_SHOWUSAGE;
417 }
418
419 owcs = ari_conf_get_owcs();
420 if (!owcs) {
421 ast_cli(a->fd, "Error getting ARI configuration\n");
422 return CLI_FAILURE;
423 }
424
425 ast_cli(a->fd, "%-32s %-15s %-32s %-7s %s\n", "Name", "Type", "Apps", "Status", "URI");
426 ast_cli(a->fd, "%.*s %.*s %.*s %.*s %.*s\n", 32, DASHES, 15, DASHES, 32, DASHES, 7, DASHES, 64, DASHES);
427
429
430 return CLI_SUCCESS;
431}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
@ OBJ_NODATA
Definition: astobj2.h:1044
static int show_owc_cb(void *obj, void *arg, int flags)
Definition: res/ari/cli.c:380
#define DASHES
Definition: res/ari/cli.c:555

References a, ao2_callback, ao2_cleanup, ari_conf_get_owcs(), ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, DASHES, NULL, OBJ_NODATA, RAII_VAR, show_owc_cb(), and ast_cli_entry::usage.

◆ ari_show_sessions()

static char * ari_show_sessions ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 556 of file res/ari/cli.c.

558{
560
561 switch (cmd) {
562 case CLI_INIT:
563 e->command = "ari show websocket sessions";
564 e->usage =
565 "Usage: ari show websocket sessions\n"
566 " Shows all ARI websocket sessions\n";
567 return NULL;
568 case CLI_GENERATE:
569 return NULL;
570 default:
571 break;
572 }
573
574 if (a->argc != 4) {
575 return CLI_SHOWUSAGE;
576 }
577
579 if (!sessions) {
580 ast_cli(a->fd, "Error getting websocket sessions\n");
581 return CLI_FAILURE;
582 }
583
584 ast_cli(a->fd, "%-*.*s %-15.15s %-32.32s %-5.5s %-16.16s\n",
586 "Connection ID",
587 "Type",
588 "RemoteAddr",
589 "State",
590 "Apps"
591 );
592 ast_cli(a->fd, "%-*.*s %-15.15s %-32.32s %-5.5s %-16.16s\n",
594
596
597 return CLI_SUCCESS;
598}
struct ao2_container * ari_websocket_get_sessions(void)
static struct unistimsession * sessions
static int show_sessions_cb(void *obj, void *arg, int flags)
Definition: res/ari/cli.c:536
#define AST_UUID_STR_LEN
Definition: uuid.h:27

References a, ao2_callback, ao2_cleanup, ari_websocket_get_sessions(), ast_cli(), AST_UUID_STR_LEN, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, DASHES, NULL, OBJ_NODATA, RAII_VAR, sessions, show_sessions_cb(), and ast_cli_entry::usage.

◆ ari_show_user()

static char * ari_show_user ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 140 of file res/ari/cli.c.

141{
144
145 if (!users) {
146 ast_cli(a->fd, "Error getting ARI configuration\n");
147 return CLI_FAILURE;
148 }
149
150 switch (cmd) {
151 case CLI_INIT:
152 e->command = "ari show user";
153 e->usage =
154 "Usage: ari show user <username>\n"
155 " Shows a specific ARI user\n";
156 return NULL;
157 case CLI_GENERATE:
159 return NULL;
160 default:
161 break;
162 }
163
164 if (a->argc != 4) {
165 return CLI_SHOWUSAGE;
166 }
167
168 user = ari_conf_get_user(a->argv[3]);
169 if (!user) {
170 ast_cli(a->fd, "User '%s' not found\n", a->argv[3]);
171 return CLI_SUCCESS;
172 }
173
174 ast_cli(a->fd, "Username: %s\n", ast_sorcery_object_get_id(user));
175 ast_cli(a->fd, "Read only?: %s\n", AST_CLI_YESNO(user->read_only));
176
177 return CLI_SUCCESS;
178}
struct ao2_container * ari_conf_get_users(void)
struct ari_conf_user * ari_conf_get_user(const char *username)
Per-user configuration options.
Definition: internal.h:84
structure to hold users read from users.conf
list of users found in the config file

References a, ao2_cleanup, ari_conf_get_user(), ari_conf_get_users(), ast_cli(), AST_CLI_YESNO, ast_sorcery_object_get_id(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sorcery_object(), NULL, RAII_VAR, and ast_cli_entry::usage.

◆ ari_show_users()

static char * ari_show_users ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 87 of file res/ari/cli.c.

89{
91
92 switch (cmd) {
93 case CLI_INIT:
94 e->command = "ari show users";
95 e->usage =
96 "Usage: ari show users\n"
97 " Shows all ARI users\n";
98 return NULL;
99 case CLI_GENERATE:
100 return NULL;
101 default:
102 break;
103 }
104
105 if (a->argc != 3) {
106 return CLI_SHOWUSAGE;
107 }
108
110 if (!users) {
111 ast_cli(a->fd, "Error getting ARI configuration\n");
112 return CLI_FAILURE;
113 }
114
115 ast_cli(a->fd, "r/o? Username\n");
116 ast_cli(a->fd, "---- --------\n");
117
119
120 return CLI_SUCCESS;
121}
static int show_users_cb(void *obj, void *arg, int flags)
Definition: res/ari/cli.c:76

References a, ao2_callback, ao2_cleanup, ari_conf_get_users(), ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, OBJ_NODATA, RAII_VAR, show_users_cb(), and ast_cli_entry::usage.

◆ ari_shut_session()

static char * ari_shut_session ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 643 of file res/ari/cli.c.

645{
648
649 if (!sessions) {
650 ast_cli(a->fd, "Error getting ARI configuration\n");
651 return CLI_FAILURE ;
652 }
653
654 switch (cmd) {
655 case CLI_INIT:
656 e->command = "ari shutdown websocket session";
657 e->usage =
658 "Usage: ari shutdown websocket session <id>\n"
659 " Shuts down ARI websocket session\n";
660 return NULL;
661 case CLI_GENERATE:
663 return NULL;
664 default:
665 break;
666 }
667
668 if (a->argc != 5) {
669 return CLI_SHOWUSAGE;
670 }
671
673 if (!session) {
674 ast_cli(a->fd, "Websocket session '%s' not found\n", a->argv[4]);
675 return CLI_FAILURE ;
676 }
677 ast_cli(a->fd, "Shutting down websocket session '%s'\n", a->argv[4]);
679
680 return CLI_SUCCESS;
681}
struct ari_ws_session * ari_websocket_get_session(const char *session_id)
void ari_websocket_shutdown(struct ari_ws_session *session)
static struct ast_mansession session
static void complete_session(struct ao2_container *container, const char *word)
Definition: res/ari/cli.c:627

References a, ao2_cleanup, ari_websocket_get_session(), ari_websocket_get_sessions(), ari_websocket_shutdown(), ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_session(), NULL, RAII_VAR, session, sessions, and ast_cli_entry::usage.

◆ ari_shut_sessions()

static char * ari_shut_sessions ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 600 of file res/ari/cli.c.

602{
603
604 switch (cmd) {
605 case CLI_INIT:
606 e->command = "ari shutdown websocket sessions";
607 e->usage =
608 "Usage: ari shutdown websocket sessions\n"
609 " Shuts down all ARI websocket sessions\n";
610 return NULL;
611 case CLI_GENERATE:
612 return NULL;
613 default:
614 break;
615 }
616
617 if (a->argc != 4) {
618 return CLI_SHOWUSAGE;
619 }
620
621 ast_cli(a->fd, "Shutting down all websocket sessions\n");
623
624 return CLI_SUCCESS;
625}
void ari_websocket_shutdown_all(void)

References a, ari_websocket_shutdown_all(), ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ ari_start_owc()

static char * ari_start_owc ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 493 of file res/ari/cli.c.

494{
497
498 if (!owcs) {
499 ast_cli(a->fd, "Error getting ARI configuration\n");
500 return CLI_FAILURE ;
501 }
502
503 switch (cmd) {
504 case CLI_INIT:
505 e->command = "ari start outbound-websocket";
506 e->usage =
507 "Usage: ari start outbound-websocket <connection id>\n"
508 " Starts a specific ARI outbound websocket\n";
509 return NULL;
510 case CLI_GENERATE:
511 complete_sorcery_object(owcs, a->word);
512 return NULL;
513 default:
514 break;
515 }
516
517 if (a->argc != 4) {
518 return CLI_SHOWUSAGE;
519 }
520
521 owc = ari_conf_get_owc(a->argv[3]);
522 if (!owc) {
523 ast_cli(a->fd, "Error getting ARI configuration\n");
524 return CLI_FAILURE;
525 }
526 ast_cli(a->fd, "Starting websocket session for outbound-websocket '%s'\n", a->argv[3]);
527
528 if (ari_outbound_websocket_start(owc) != 0) {
529 ast_cli(a->fd, "Error starting outbound websocket\n");
530 return CLI_FAILURE ;
531 }
532
533 return CLI_SUCCESS;
534}
int ari_outbound_websocket_start(struct ari_conf_outbound_websocket *owc)

References a, ao2_cleanup, ari_conf_get_owc(), ari_conf_get_owcs(), ari_outbound_websocket_start(), ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sorcery_object(), NULL, RAII_VAR, and ast_cli_entry::usage.

◆ complete_app()

static void complete_app ( struct ao2_container container,
const char *  word 
)
static

Definition at line 263 of file res/ari/cli.c.

265{
266 size_t wordlen = strlen(word);
267 void *object;
269
270 while ((object = ao2_iterator_next(&i))) {
271 if (!strncasecmp(word, object, wordlen)) {
273 }
274 ao2_ref(object, -1);
275 }
277}
short word
struct ao2_container * container
Definition: res_fax.c:531

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_completion_add(), ast_strdup, and container.

Referenced by ari_set_debug(), and ari_show_app().

◆ complete_session()

static void complete_session ( struct ao2_container container,
const char *  word 
)
static

Definition at line 627 of file res/ari/cli.c.

629{
630 size_t wordlen = strlen(word);
631 struct ari_ws_session *session;
633
634 while ((session = ao2_iterator_next(&i))) {
635 if (!strncasecmp(word, session->session_id, wordlen)) {
637 }
638 ao2_ref(session, -1);
639 }
641}

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_completion_add(), ast_strdup, container, and session.

Referenced by ari_shut_session().

◆ complete_sorcery_object()

static void complete_sorcery_object ( struct ao2_container container,
const char *  word 
)
static

Definition at line 123 of file res/ari/cli.c.

125{
126 size_t wordlen = strlen(word);
127 void *object;
129
130 while ((object = ao2_iterator_next(&i))) {
131 const char *id = ast_sorcery_object_get_id(object);
132 if (!strncasecmp(word, id, wordlen)) {
134 }
135 ao2_ref(object, -1);
136 }
138}

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_completion_add(), ast_sorcery_object_get_id(), ast_strdup, and container.

Referenced by ari_show_owc(), ari_show_user(), and ari_start_owc().

◆ show_owc_cb()

static int show_owc_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 380 of file res/ari/cli.c.

381{
382 struct ari_conf_outbound_websocket *owc = obj;
383 const char *id = ast_sorcery_object_get_id(owc);
385 struct ast_cli_args *a = arg;
386
387 ast_cli(a->fd, "%-32s %-15s %-32s %-7s %s\n",
388 id,
390 owc->apps,
391 invalid_fields == ARI_OWC_FIELD_NONE ? "valid" : "INVALID",
392 owc->websocket_client->uri);
393 return 0;
394}
const ast_string_field apps
Definition: internal.h:116
struct ast_websocket_client * websocket_client
Definition: internal.h:119
const ast_string_field uri
enum ast_websocket_type connection_type

References a, ari_conf_outbound_websocket::apps, ari_conf_owc_get_invalid_fields(), ARI_OWC_FIELD_NONE, ari_websocket_type_to_str(), ast_cli(), ast_sorcery_object_get_id(), ast_websocket_client::connection_type, ast_websocket_client::uri, and ari_conf_outbound_websocket::websocket_client.

Referenced by ari_show_owcs().

◆ show_sessions_cb()

static int show_sessions_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 536 of file res/ari/cli.c.

537{
538 struct ari_ws_session *session = obj;
539 struct ast_cli_args *a = arg;
540 char *apps = ast_vector_string_join(&session->websocket_apps, ",");
541
542 ast_cli(a->fd, "%-*s %-15s %-32s %-5s %s\n",
544 session->session_id,
546 S_OR(session->remote_addr, "N/A"),
548 ? "N/A" : (session->connected ? "Up" : "Down"),
549 S_OR(apps, ""));
550
551 ast_free(apps);
552 return 0;
553}
@ AST_WS_TYPE_CLIENT_PER_CALL_CONFIG
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
char * ast_vector_string_join(struct ast_vector_string *vec, const char *delim)
Join the elements of a string vector into a single string.
Definition: strings.c:406

References a, ari_websocket_type_to_str(), ast_cli(), ast_free, AST_UUID_STR_LEN, ast_vector_string_join(), AST_WS_TYPE_CLIENT_PER_CALL_CONFIG, S_OR, and session.

Referenced by ari_show_sessions().

◆ show_users_cb()

static int show_users_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 76 of file res/ari/cli.c.

77{
78 struct ari_conf_user *user = obj;
79 struct ast_cli_args *a = arg;
80
81 ast_cli(a->fd, "%-4s %s\n",
82 AST_CLI_YESNO(user->read_only),
84 return 0;
85}

References a, ast_cli(), AST_CLI_YESNO, and ast_sorcery_object_get_id().

Referenced by ari_show_users().

Variable Documentation

◆ cli_ari

struct ast_cli_entry cli_ari[]
static

Definition at line 683 of file res/ari/cli.c.

Referenced by ari_cli_register(), and ari_cli_unregister().