Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
Macros | Functions | Variables
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.
 
void ari_cli_unregister (void)
 Unregister CLI commands for ARI.
 
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 401 of file res/ari/cli.c.

◆ DASHES [2/2]

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

Definition at line 401 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 704 of file res/ari/cli.c.

704 {
706}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
static struct ast_cli_entry cli_ari[]
#define ARRAY_LEN(a)
Definition utils.h:706

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 708 of file res/ari/cli.c.

708 {
710}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408

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 185 of file res/ari/cli.c.

186{
187 RAII_VAR(char *, crypted, NULL, ast_free);
188
189 switch (cmd) {
190 case CLI_INIT:
191 e->command = "ari mkpasswd";
192 e->usage =
193 "Usage: ari mkpasswd <password>\n"
194 " Encrypts a password for use in ari.conf\n"
195 " Be aware that the password will be shown in the\n"
196 " command line history. The mkpasswd shell command\n"
197 " may be preferable.\n"
198 ;
199 return NULL;
200 case CLI_GENERATE:
201 return NULL;
202 default:
203 break;
204 }
205
206 if (a->argc != 3) {
207 return CLI_SHOWUSAGE;
208 }
209
210 crypted = ast_crypt_encrypt(a->argv[2]);
211 if (!crypted) {
212 ast_cli(a->fd, "Failed to encrypt password\n");
213 return CLI_FAILURE;
214 }
215
216 ast_cli(a->fd,
217 "; Copy the following two lines into ari.conf\n");
218 ast_cli(a->fd, "password_format = crypt\n");
219 ast_cli(a->fd, "password = %s\n", crypted);
220
221 return CLI_SUCCESS;
222}
#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:981
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 325 of file res/ari/cli.c.

326{
328 void *app;
329 int debug;
330
331 if (!apps) {
332 ast_cli(a->fd, "Error getting ARI applications\n");
333 return CLI_FAILURE;
334 }
335
336 switch (cmd) {
337 case CLI_INIT:
338 e->command = "ari set debug";
339 e->usage =
340 "Usage: ari set debug <application|all> <on|off>\n"
341 " Enable or disable debugging on a specific application.\n"
342 ;
343 return NULL;
344 case CLI_GENERATE:
345 if (a->argc == 3) {
347 complete_app(apps, a->word);
348 } else if (a->argc == 4) {
351 }
352 return NULL;
353 default:
354 break;
355 }
356
357 if (a->argc != 5) {
358 return CLI_SHOWUSAGE;
359 }
360
361 debug = !strcmp(a->argv[4], "on");
362
363 if (!strcmp(a->argv[3], "all")) {
365 ast_cli(a->fd, "Debugging on all applications %s\n",
366 debug ? "enabled" : "disabled");
367 return CLI_SUCCESS;
368 }
369
370 app = stasis_app_get_by_name(a->argv[3]);
371 if (!app) {
372 return CLI_FAILURE;
373 }
374
376 ast_cli(a->fd, "Debugging on '%s' %s\n",
378 debug ? "enabled" : "disabled");
379
380 ao2_ref(app, -1);
381
382 return CLI_SUCCESS;
383}
static const char app[]
#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:2845
static void complete_app(struct ao2_container *container, const char *word)
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.
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
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:69

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:58

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 284 of file res/ari/cli.c.

285{
286 void *app;
288
289 if (!apps) {
290 ast_cli(a->fd, "Error getting ARI applications\n");
291 return CLI_FAILURE;
292 }
293
294 switch (cmd) {
295 case CLI_INIT:
296 e->command = "ari show app";
297 e->usage =
298 "Usage: ari show app <application>\n"
299 " Provide detailed information about a registered application.\n"
300 ;
301 return NULL;
302 case CLI_GENERATE:
303 complete_app(apps, a->word);
304 return NULL;
305 default:
306 break;
307 }
308
309 if (a->argc != 4) {
310 return CLI_SHOWUSAGE;
311 }
312
313 app = stasis_app_get_by_name(a->argv[3]);
314 if (!app) {
315 return CLI_FAILURE;
316 }
317
319
320 ao2_ref(app, -1);
321
322 return CLI_SUCCESS;
323}
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 224 of file res/ari/cli.c.

225{
226 struct ao2_container *apps;
227 struct ao2_iterator it_apps;
228 char *app;
229
230 switch (cmd) {
231 case CLI_INIT:
232 e->command = "ari show apps";
233 e->usage =
234 "Usage: ari show apps\n"
235 " Lists all registered applications.\n"
236 ;
237 return NULL;
238 case CLI_GENERATE:
239 return NULL;
240 default:
241 break;
242 }
243
244 if (a->argc != 3) {
245 return CLI_SHOWUSAGE;
246 }
247
249 if (!apps) {
250 ast_cli(a->fd, "Unable to retrieve registered applications!\n");
251 return CLI_FAILURE;
252 }
253
254 ast_cli(a->fd, "Application Name \n");
255 ast_cli(a->fd, "=========================\n");
256 it_apps = ao2_iterator_init(apps, 0);
257 while ((app = ao2_iterator_next(&it_apps))) {
258 ast_cli(a->fd, "%s\n", app);
259 ao2_ref(app, -1);
260 }
261
262 ao2_iterator_destroy(&it_apps);
263 ao2_ref(apps, -1);
264
265 return CLI_SUCCESS;
266}
#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.
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, 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 438 of file res/ari/cli.c.

439{
442 const char *id = NULL;
443 enum ari_conf_owc_fields invalid_fields;
444
445 switch (cmd) {
446 case CLI_INIT:
447 e->command = "ari show outbound-websocket";
448 e->usage =
449 "Usage: ari show outbound-websocket <connection id>\n"
450 " Shows a specific ARI outbound websocket\n";
451 return NULL;
452 case CLI_GENERATE:
453 complete_sorcery_object(owcs, a->word);
454 return NULL;
455 default:
456 break;
457 }
458
459 if (a->argc != 4) {
460 return CLI_SHOWUSAGE;
461 }
462
463 owc = ari_conf_get_owc(a->argv[3]);
464 if (!owc) {
465 ast_cli(a->fd, "Error getting ARI configuration\n");
466 return CLI_FAILURE;
467 }
469 invalid_fields = ari_conf_owc_get_invalid_fields(id);
470
471 ast_cli(a->fd, "[%s] %s\n", id,
472 invalid_fields == ARI_OWC_FIELD_NONE ? "" : "**INVALID**");
473 ast_cli(a->fd, "uri = %s\n", owc->websocket_client->uri);
474 ast_cli(a->fd, "protocols = %s\n", owc->websocket_client->protocols);
475 ast_cli(a->fd, "apps = %s%s\n", owc->apps,
476 invalid_fields & ARI_OWC_FIELD_APPS ? " (invalid)" : "");
477 ast_cli(a->fd, "username = %s\n", owc->websocket_client->username);
478 ast_cli(a->fd, "password = %s\n", S_COR(owc->websocket_client->password, "********", ""));
479 ast_cli(a->fd, "local_ari_user = %s%s\n", owc->local_ari_user,
480 invalid_fields & ARI_OWC_FIELD_LOCAL_ARI_USER ? " (invalid)" : "");
481 ast_cli(a->fd, "connection_type = %s\n", ari_websocket_type_to_str(owc->websocket_client->connection_type));
482 ast_cli(a->fd, "subscribe_all = %s\n", AST_CLI_YESNO(owc->subscribe_all));
483 ast_cli(a->fd, "connec_timeout = %d\n", owc->websocket_client->connect_timeout);
484 ast_cli(a->fd, "reconnect_attempts = %d\n", owc->websocket_client->reconnect_attempts);
485 ast_cli(a->fd, "reconnect_interval = %d\n", owc->websocket_client->reconnect_interval);
486 ast_cli(a->fd, "tls_enabled = %s\n", AST_CLI_YESNO(owc->websocket_client->tls_enabled));
487 ast_cli(a->fd, "ca_list_file = %s\n", owc->websocket_client->ca_list_file);
488 ast_cli(a->fd, "ca_list_path = %s\n", owc->websocket_client->ca_list_path);
489 ast_cli(a->fd, "cert_file = %s\n", owc->websocket_client->cert_file);
490 ast_cli(a->fd, "priv_key_file = %s\n", owc->websocket_client->priv_key_file);
491 ast_cli(a->fd, "verify_server = %s\n", AST_CLI_YESNO(owc->websocket_client->verify_server_cert));
492 ast_cli(a->fd, "verify_server_hostname = %s\n", AST_CLI_YESNO(owc->websocket_client->verify_server_hostname));
493 ast_cli(a->fd, "\n");
494
495 return CLI_SUCCESS;
496}
const char * ari_websocket_type_to_str(enum ast_websocket_type type)
ari_conf_owc_fields
Definition internal.h:99
@ ARI_OWC_FIELD_APPS
Definition internal.h:102
@ ARI_OWC_FIELD_NONE
Definition internal.h:100
@ ARI_OWC_FIELD_LOCAL_ARI_USER
Definition internal.h:103
static void complete_sorcery_object(struct ao2_container *container, const char *word)
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:2381
#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 402 of file res/ari/cli.c.

404{
405 RAII_VAR(struct ao2_container *, owcs, NULL, ao2_cleanup);
406
407 switch (cmd) {
408 case CLI_INIT:
409 e->command = "ari show outbound-websockets";
410 e->usage =
411 "Usage: ari show outbound-websockets\n"
412 " Shows all ARI outbound-websockets\n";
413 return NULL;
414 case CLI_GENERATE:
415 return NULL;
416 default:
417 break;
418 }
419
420 if (a->argc != 3) {
421 return CLI_SHOWUSAGE;
422 }
423
424 owcs = ari_conf_get_owcs();
425 if (!owcs) {
426 ast_cli(a->fd, "Error getting ARI configuration\n");
427 return CLI_FAILURE;
428 }
429
430 ast_cli(a->fd, "%-32s %-15s %-32s %-7s %s\n", "Name", "Type", "Apps", "Status", "URI");
431 ast_cli(a->fd, "%.*s %.*s %.*s %.*s %.*s\n", 32, DASHES, 15, DASHES, 32, DASHES, 7, DASHES, 64, DASHES);
432
434
435 return CLI_SUCCESS;
436}
#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)
#define DASHES

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 561 of file res/ari/cli.c.

563{
565
566 switch (cmd) {
567 case CLI_INIT:
568 e->command = "ari show websocket sessions";
569 e->usage =
570 "Usage: ari show websocket sessions\n"
571 " Shows all ARI websocket sessions\n";
572 return NULL;
573 case CLI_GENERATE:
574 return NULL;
575 default:
576 break;
577 }
578
579 if (a->argc != 4) {
580 return CLI_SHOWUSAGE;
581 }
582
584 if (!sessions) {
585 ast_cli(a->fd, "Error getting websocket sessions\n");
586 return CLI_FAILURE;
587 }
588
589 ast_cli(a->fd, "%-*.*s %-15.15s %-32.32s %-5.5s %-16.16s\n",
591 "Connection ID",
592 "Type",
593 "RemoteAddr",
594 "State",
595 "Apps"
596 );
597 ast_cli(a->fd, "%-*.*s %-15.15s %-32.32s %-5.5s %-16.16s\n",
599
601
602 return CLI_SUCCESS;
603}
struct ao2_container * ari_websocket_get_sessions(void)
static struct unistimsession * sessions
static int show_sessions_cb(void *obj, void *arg, int flags)
#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 141 of file res/ari/cli.c.

142{
145
146 if (!users) {
147 ast_cli(a->fd, "Error getting ARI configuration\n");
148 return CLI_FAILURE;
149 }
150
151 switch (cmd) {
152 case CLI_INIT:
153 e->command = "ari show user";
154 e->usage =
155 "Usage: ari show user <username>\n"
156 " Shows a specific ARI user\n";
157 return NULL;
158 case CLI_GENERATE:
160 return NULL;
161 default:
162 break;
163 }
164
165 if (a->argc != 4) {
166 return CLI_SHOWUSAGE;
167 }
168
169 user = ari_conf_get_user(a->argv[3]);
170 if (!user) {
171 ast_cli(a->fd, "User '%s' not found\n", a->argv[3]);
172 return CLI_SUCCESS;
173 }
174
175 ast_cli(a->fd, "Username: %s\n", ast_sorcery_object_get_id(user));
176 ast_cli(a->fd, "Read only?: %s\n", AST_CLI_YESNO(user->read_only));
177 ast_cli(a->fd, "ACL?: %s\n", AST_CLI_YESNO(user->acl && !ast_acl_list_is_empty(user->acl)));
178 if (!ast_acl_list_is_empty(user->acl)) {
179 ast_acl_output(a->fd, user->acl, NULL);
180 }
181
182 return CLI_SUCCESS;
183}
void ast_acl_output(int fd, struct ast_acl_list *acl, const char *prefix)
output an ACL to the provided fd
Definition acl.c:1115
int ast_acl_list_is_empty(struct ast_acl_list *acl_list)
Determines if an ACL is empty or if it contains entries.
Definition acl.c:540
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:85
structure to hold users read from phoneprov_users.conf
list of users found in the config file

References a, ao2_cleanup, ari_conf_get_user(), ari_conf_get_users(), ast_acl_list_is_empty(), ast_acl_output(), 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 88 of file res/ari/cli.c.

90{
92
93 switch (cmd) {
94 case CLI_INIT:
95 e->command = "ari show users";
96 e->usage =
97 "Usage: ari show users\n"
98 " Shows all ARI users\n";
99 return NULL;
100 case CLI_GENERATE:
101 return NULL;
102 default:
103 break;
104 }
105
106 if (a->argc != 3) {
107 return CLI_SHOWUSAGE;
108 }
109
111 if (!users) {
112 ast_cli(a->fd, "Error getting ARI configuration\n");
113 return CLI_FAILURE;
114 }
115
116 ast_cli(a->fd, "r/o? ACL? Username\n");
117 ast_cli(a->fd, "---- ---- --------\n");
118
120
121 return CLI_SUCCESS;
122}
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 648 of file res/ari/cli.c.

650{
653
654 if (!sessions) {
655 ast_cli(a->fd, "Error getting ARI configuration\n");
656 return CLI_FAILURE ;
657 }
658
659 switch (cmd) {
660 case CLI_INIT:
661 e->command = "ari shutdown websocket session";
662 e->usage =
663 "Usage: ari shutdown websocket session <id>\n"
664 " Shuts down ARI websocket session\n";
665 return NULL;
666 case CLI_GENERATE:
668 return NULL;
669 default:
670 break;
671 }
672
673 if (a->argc != 5) {
674 return CLI_SHOWUSAGE;
675 }
676
678 if (!session) {
679 ast_cli(a->fd, "Websocket session '%s' not found\n", a->argv[4]);
680 return CLI_FAILURE ;
681 }
682 ast_cli(a->fd, "Shutting down websocket session '%s'\n", a->argv[4]);
684
685 return CLI_SUCCESS;
686}
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)

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 605 of file res/ari/cli.c.

607{
608
609 switch (cmd) {
610 case CLI_INIT:
611 e->command = "ari shutdown websocket sessions";
612 e->usage =
613 "Usage: ari shutdown websocket sessions\n"
614 " Shuts down all ARI websocket sessions\n";
615 return NULL;
616 case CLI_GENERATE:
617 return NULL;
618 default:
619 break;
620 }
621
622 if (a->argc != 4) {
623 return CLI_SHOWUSAGE;
624 }
625
626 ast_cli(a->fd, "Shutting down all websocket sessions\n");
628
629 return CLI_SUCCESS;
630}
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 498 of file res/ari/cli.c.

499{
502
503 if (!owcs) {
504 ast_cli(a->fd, "Error getting ARI configuration\n");
505 return CLI_FAILURE ;
506 }
507
508 switch (cmd) {
509 case CLI_INIT:
510 e->command = "ari start outbound-websocket";
511 e->usage =
512 "Usage: ari start outbound-websocket <connection id>\n"
513 " Starts a specific ARI outbound websocket\n";
514 return NULL;
515 case CLI_GENERATE:
516 complete_sorcery_object(owcs, a->word);
517 return NULL;
518 default:
519 break;
520 }
521
522 if (a->argc != 4) {
523 return CLI_SHOWUSAGE;
524 }
525
526 owc = ari_conf_get_owc(a->argv[3]);
527 if (!owc) {
528 ast_cli(a->fd, "Error getting ARI configuration\n");
529 return CLI_FAILURE;
530 }
531 ast_cli(a->fd, "Starting websocket session for outbound-websocket '%s'\n", a->argv[3]);
532
533 if (ari_outbound_websocket_start(owc) != 0) {
534 ast_cli(a->fd, "Error starting outbound websocket\n");
535 return CLI_FAILURE ;
536 }
537
538 return CLI_SUCCESS;
539}
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 268 of file res/ari/cli.c.

270{
271 size_t wordlen = strlen(word);
272 void *object;
274
275 while ((object = ao2_iterator_next(&i))) {
276 if (!strncasecmp(word, object, wordlen)) {
278 }
279 ao2_ref(object, -1);
280 }
282}
short word
struct ao2_container * container
Definition res_fax.c:603

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 632 of file res/ari/cli.c.

634{
635 size_t wordlen = strlen(word);
636 struct ari_ws_session *session;
638
639 while ((session = ao2_iterator_next(&i))) {
640 if (!strncasecmp(word, session->session_id, wordlen)) {
642 }
643 ao2_ref(session, -1);
644 }
646}

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 124 of file res/ari/cli.c.

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

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 385 of file res/ari/cli.c.

386{
387 struct ari_conf_outbound_websocket *owc = obj;
388 const char *id = ast_sorcery_object_get_id(owc);
390 struct ast_cli_args *a = arg;
391
392 ast_cli(a->fd, "%-32s %-15s %-32s %-7s %s\n",
393 id,
395 owc->apps,
396 invalid_fields == ARI_OWC_FIELD_NONE ? "valid" : "INVALID",
397 owc->websocket_client->uri);
398 return 0;
399}
const ast_string_field apps
Definition internal.h:119
struct ast_websocket_client * websocket_client
Definition internal.h:122
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 541 of file res/ari/cli.c.

542{
543 struct ari_ws_session *session = obj;
544 struct ast_cli_args *a = arg;
545 char *apps = ast_vector_string_join(&session->websocket_apps, ",");
546
547 ast_cli(a->fd, "%-*s %-15s %-32s %-5s %s\n",
549 session->session_id,
551 S_OR(session->remote_addr, "N/A"),
553 ? "N/A" : (session->connected ? "Up" : "Down"),
554 S_OR(apps, ""));
555
556 ast_free(apps);
557 return 0;
558}
static int connected
Definition cdr_pgsql.c:73
@ 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 %-4s %s\n",
82 AST_CLI_YESNO(user->read_only),
85 return 0;
86}

References a, ast_acl_list_is_empty(), 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 688 of file res/ari/cli.c.

688 {
689 AST_CLI_DEFINE(ari_show, "Show ARI settings"),
690 AST_CLI_DEFINE(ari_show_users, "List ARI users"),
691 AST_CLI_DEFINE(ari_show_user, "List single ARI user"),
692 AST_CLI_DEFINE(ari_mkpasswd, "Encrypts a password"),
693 AST_CLI_DEFINE(ari_show_apps, "List registered ARI applications"),
694 AST_CLI_DEFINE(ari_show_app, "Display details of a registered ARI application"),
695 AST_CLI_DEFINE(ari_set_debug, "Enable/disable debugging of an ARI application"),
696 AST_CLI_DEFINE(ari_show_owcs, "List outbound websocket connections"),
697 AST_CLI_DEFINE(ari_show_owc, "Show outbound websocket connection"),
698 AST_CLI_DEFINE(ari_start_owc, "Start outbound websocket connection"),
699 AST_CLI_DEFINE(ari_show_sessions, "Show websocket sessions"),
700 AST_CLI_DEFINE(ari_shut_session, "Shutdown websocket session"),
701 AST_CLI_DEFINE(ari_shut_sessions, "Shutdown websocket sessions"),
702};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
static char * ari_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition res/ari/cli.c:34
static char * ari_mkpasswd(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_set_debug(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_owc(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_show_app(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_shut_sessions(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)
Definition res/ari/cli.c:88
static char * ari_start_owc(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)

Referenced by ari_cli_register(), and ari_cli_unregister().