Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | 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 "internal.h"
Include dependency graph for res/ari/cli.c:

Go to the source code of this file.

Data Structures

struct  app_complete
 
struct  user_complete
 

Functions

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_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)
 
int ast_ari_cli_register (void)
 Register CLI commands for ARI. More...
 
void ast_ari_cli_unregister (void)
 Unregister CLI commands for ARI. More...
 
static char * complete_ari_app (struct ast_cli_args *a, int include_all)
 
static int complete_ari_app_search (void *obj, void *arg, void *data, int flags)
 
static char * complete_ari_show_user (struct ast_cli_args *a)
 
static char * complete_ari_user (struct ast_cli_args *a)
 
static int complete_ari_user_search (void *obj, void *arg, void *data, 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.

Function Documentation

◆ ari_mkpasswd()

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

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

212{
213 RAII_VAR(char *, crypted, NULL, ast_free);
214
215 switch (cmd) {
216 case CLI_INIT:
217 e->command = "ari mkpasswd";
218 e->usage =
219 "Usage: ari mkpasswd <password>\n"
220 " Encrypts a password for use in ari.conf\n"
221 " Be aware that the password will be shown in the\n"
222 " command line history. The mkpasswd shell command\n"
223 " may be preferable.\n"
224 ;
225 return NULL;
226 case CLI_GENERATE:
227 return NULL;
228 default:
229 break;
230 }
231
232 if (a->argc != 3) {
233 return CLI_SHOWUSAGE;
234 }
235
236 crypted = ast_crypt_encrypt(a->argv[2]);
237 if (!crypted) {
238 ast_cli(a->fd, "Failed to encrypt password\n");
239 return CLI_FAILURE;
240 }
241
242 ast_cli(a->fd,
243 "; Copy the following two lines into ari.conf\n");
244 ast_cli(a->fd, "password_format = crypt\n");
245 ast_cli(a->fd, "password = %s\n", crypted);
246
247 return CLI_SUCCESS;
248}
#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 374 of file res/ari/cli.c.

375{
376 void *app;
377 int debug;
378
379 switch (cmd) {
380 case CLI_INIT:
381 e->command = "ari set debug";
382 e->usage =
383 "Usage: ari set debug <application|all> <on|off>\n"
384 " Enable or disable debugging on a specific application.\n"
385 ;
386 return NULL;
387 case CLI_GENERATE:
388 return complete_ari_app(a, 1);
389 default:
390 break;
391 }
392
393 if (a->argc != 5) {
394 return CLI_SHOWUSAGE;
395 }
396
397 debug = !strcmp(a->argv[4], "on");
398
399 if (!strcmp(a->argv[3], "all")) {
401 ast_cli(a->fd, "Debugging on all applications %s\n",
402 debug ? "enabled" : "disabled");
403 return CLI_SUCCESS;
404 }
405
406 app = stasis_app_get_by_name(a->argv[3]);
407 if (!app) {
408 return CLI_FAILURE;
409 }
410
412 ast_cli(a->fd, "Debugging on '%s' %s\n",
414 debug ? "enabled" : "disabled");
415
416 ao2_ref(app, -1);
417
418 return CLI_SUCCESS;
419}
static const char app[]
Definition: app_adsiprog.c:56
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static char * complete_ari_app(struct ast_cli_args *a, int include_all)
Definition: res/ari/cli.c:311
static int debug
Global debug status.
Definition: res_xmpp.c:441
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:1697
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.

References a, ao2_ref, app, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_ari_app(), debug, NULL, 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 32 of file res/ari/cli.c.

33{
35
36 switch (cmd) {
37 case CLI_INIT:
38 e->command = "ari show status";
39 e->usage =
40 "Usage: ari show status\n"
41 " Shows all ARI settings\n";
42 return NULL;
43 case CLI_GENERATE:
44 return NULL;
45 default:
46 break;
47 }
48
49 if (a->argc != 3) {
50 return CLI_SHOWUSAGE;
51 }
52
54
55 if (!conf) {
56 ast_cli(a->fd, "Error getting ARI configuration\n");
57 return CLI_FAILURE;
58 }
59
60 ast_cli(a->fd, "ARI Status:\n");
61 ast_cli(a->fd, "Enabled: %s\n", AST_CLI_YESNO(conf->general->enabled));
62 ast_cli(a->fd, "Output format: ");
63 if (conf->general->format & AST_JSON_PRETTY) {
64 ast_cli(a->fd, "pretty");
65 } else {
66 ast_cli(a->fd, "compact");
67 }
68 ast_cli(a->fd, "\n");
69 ast_cli(a->fd, "Auth realm: %s\n", conf->general->auth_realm);
70 ast_cli(a->fd, "Allowed Origins: %s\n", conf->general->allowed_origins);
71 ast_cli(a->fd, "User count: %d\n", ao2_container_count(conf->users));
72 return CLI_SUCCESS;
73}
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#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 ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
All configuration options for ARI.
Definition: internal.h:54
All configuration options for http media cache.
struct conf_general_options * general

References a, ao2_cleanup, ao2_container_count(), ast_ari_config_get(), ast_cli(), AST_CLI_YESNO, AST_JSON_PRETTY, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, conf::general, 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 340 of file res/ari/cli.c.

341{
342 void *app;
343
344 switch (cmd) {
345 case CLI_INIT:
346 e->command = "ari show app";
347 e->usage =
348 "Usage: ari show app <application>\n"
349 " Provide detailed information about a registered application.\n"
350 ;
351 return NULL;
352 case CLI_GENERATE:
353 return complete_ari_app(a, 0);
354 default:
355 break;
356 }
357
358 if (a->argc != 4) {
359 return CLI_SHOWUSAGE;
360 }
361
362 app = stasis_app_get_by_name(a->argv[3]);
363 if (!app) {
364 return CLI_FAILURE;
365 }
366
368
369 ao2_ref(app, -1);
370
371 return CLI_SUCCESS;
372}
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_ref, app, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_ari_app(), NULL, 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 250 of file res/ari/cli.c.

251{
252 struct ao2_container *apps;
253 struct ao2_iterator it_apps;
254 char *app;
255
256 switch (cmd) {
257 case CLI_INIT:
258 e->command = "ari show apps";
259 e->usage =
260 "Usage: ari show apps\n"
261 " Lists all registered applications.\n"
262 ;
263 return NULL;
264 case CLI_GENERATE:
265 return NULL;
266 default:
267 break;
268 }
269
270 if (a->argc != 3) {
271 return CLI_SHOWUSAGE;
272 }
273
275 if (!apps) {
276 ast_cli(a->fd, "Unable to retrieve registered applications!\n");
277 return CLI_FAILURE;
278 }
279
280 ast_cli(a->fd, "Application Name \n");
281 ast_cli(a->fd, "=========================\n");
282 it_apps = ao2_iterator_init(apps, 0);
283 while ((app = ao2_iterator_next(&it_apps))) {
284 ast_cli(a->fd, "%-25.25s\n", app);
285 ao2_ref(app, -1);
286 }
287
288 ao2_iterator_destroy(&it_apps);
289 ao2_ref(apps, -1);
290
291 return CLI_SUCCESS;
292}
#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
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
Definition: res_stasis.c:1711
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
Registered applications container.
Definition: pbx_app.c:67

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_user()

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

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

171{
174
175 switch (cmd) {
176 case CLI_INIT:
177 e->command = "ari show user";
178 e->usage =
179 "Usage: ari show user <username>\n"
180 " Shows a specific ARI user\n";
181 return NULL;
182 case CLI_GENERATE:
184 default:
185 break;
186 }
187
188 if (a->argc != 4) {
189 return CLI_SHOWUSAGE;
190 }
191
193
194 if (!conf) {
195 ast_cli(a->fd, "Error getting ARI configuration\n");
196 return CLI_FAILURE;
197 }
198
199 user = ao2_find(conf->users, a->argv[3], OBJ_KEY);
200 if (!user) {
201 ast_cli(a->fd, "User '%s' not found\n", a->argv[3]);
202 return CLI_SUCCESS;
203 }
204
205 ast_cli(a->fd, "Username: %s\n", user->username);
206 ast_cli(a->fd, "Read only?: %s\n", AST_CLI_YESNO(user->read_only));
207
208 return CLI_SUCCESS;
209}
#define OBJ_KEY
Definition: astobj2.h:1151
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
static char * complete_ari_show_user(struct ast_cli_args *a)
Definition: res/ari/cli.c:161
Per-user configuration options.
Definition: internal.h:96
structure to hold users read from users.conf

References a, ao2_cleanup, ao2_find, ast_ari_config_get(), ast_cli(), AST_CLI_YESNO, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_ari_show_user(), NULL, OBJ_KEY, 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 86 of file res/ari/cli.c.

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

References a, ao2_callback, ao2_cleanup, ast_ari_config_get(), 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.

◆ ast_ari_cli_register()

int ast_ari_cli_register ( void  )

Register CLI commands for ARI.

Returns
0 on success.
Non-zero on error.

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

431 {
433}
#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:421
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, and cli_ari.

Referenced by load_module().

◆ ast_ari_cli_unregister()

void ast_ari_cli_unregister ( void  )

Unregister CLI commands for ARI.

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

435 {
437}
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().

◆ complete_ari_app()

static char * complete_ari_app ( struct ast_cli_args a,
int  include_all 
)
static

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

312{
314 RAII_VAR(char *, app, NULL, ao2_cleanup);
315
316 struct app_complete search = {
317 .state = a->n,
318 };
319
320 if (a->pos != 3) {
321 return NULL;
322 }
323
324 if (!apps) {
325 ast_cli(a->fd, "Error getting ARI applications\n");
326 return CLI_FAILURE;
327 }
328
329 if (include_all && ast_strlen_zero(a->word)) {
331 }
332
335 complete_ari_app_search, (char*)a->word, &search);
336
337 return app ? ast_strdup(app) : NULL;
338}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1723
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
static int complete_ari_app_search(void *obj, void *arg, void *data, int flags)
Definition: res/ari/cli.c:301
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
Definition: strings.c:205

References a, ao2_callback_data, ao2_cleanup, app, ast_cli(), ast_str_container_add(), ast_strdup, ast_strlen_zero(), CLI_FAILURE, complete_ari_app_search(), NULL, OBJ_SEARCH_PARTIAL_KEY, RAII_VAR, stasis_app_get_all(), and app_complete::state.

Referenced by ari_set_debug(), and ari_show_app().

◆ complete_ari_app_search()

static int complete_ari_app_search ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

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

302{
303 struct app_complete *search = data;
304
305 if (++search->which > search->state) {
306 return CMP_MATCH;
307 }
308 return 0;
309}
@ CMP_MATCH
Definition: astobj2.h:1027

References CMP_MATCH, app_complete::state, and app_complete::which.

Referenced by complete_ari_app().

◆ complete_ari_show_user()

static char * complete_ari_show_user ( struct ast_cli_args a)
static

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

162{
163 if (a->pos == 3) {
164 return complete_ari_user(a);
165 }
166
167 return NULL;
168}
static char * complete_ari_user(struct ast_cli_args *a)
Definition: res/ari/cli.c:139

References a, complete_ari_user(), and NULL.

Referenced by ari_show_user().

◆ complete_ari_user()

static char * complete_ari_user ( struct ast_cli_args a)
static

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

140{
143
144 struct user_complete search = {
145 .state = a->n,
146 };
147
149 if (!conf) {
150 ast_cli(a->fd, "Error getting ARI configuration\n");
151 return CLI_FAILURE;
152 }
153
154 user = ao2_callback_data(conf->users,
155 ast_strlen_zero(a->word) ? 0 : OBJ_PARTIAL_KEY,
156 complete_ari_user_search, (char*)a->word, &search);
157
158 return user ? ast_strdup(user->username) : NULL;
159}
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1152
static int complete_ari_user_search(void *obj, void *arg, void *data, int flags)
Definition: res/ari/cli.c:129

References a, ao2_callback_data, ao2_cleanup, ast_ari_config_get(), ast_cli(), ast_strdup, ast_strlen_zero(), CLI_FAILURE, complete_ari_user_search(), NULL, OBJ_PARTIAL_KEY, RAII_VAR, and user_complete::state.

Referenced by complete_ari_show_user().

◆ complete_ari_user_search()

static int complete_ari_user_search ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

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

130{
131 struct user_complete *search = data;
132
133 if (++search->which > search->state) {
134 return CMP_MATCH;
135 }
136 return 0;
137}

References CMP_MATCH, user_complete::state, and user_complete::which.

Referenced by complete_ari_user().

◆ show_users_cb()

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

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

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

References a, ast_cli(), and AST_CLI_YESNO.

Referenced by ari_show_users().

Variable Documentation

◆ cli_ari

struct ast_cli_entry cli_ari[]
static

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

Referenced by ast_ari_cli_register(), and ast_ari_cli_unregister().