res/ari/cli.c File Reference

Command line for ARI. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "internal.h"

Include dependency graph for res/ari/cli.c:

Go to the source code of this file.

Data Structures

struct  user_complete

Functions

static char * ari_mkpasswd (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_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.
void ast_ari_cli_unregister (void)
 Unregister CLI commands for ARI.
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@digium.com>

Definition in file res/ari/cli.c.


Function Documentation

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

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

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

00216 {
00217    RAII_VAR(char *, crypted, NULL, ast_free);
00218 
00219    switch (cmd) {
00220    case CLI_INIT:
00221       e->command = "ari mkpasswd";
00222       e->usage =
00223          "Usage: ari mkpasswd <password>\n"
00224          "       Encrypts a password for use in ari.conf\n"
00225          "       Be aware that the password will be shown in the\n"
00226          "       command line history. The mkpasswd shell command\n"
00227          "       may be preferable.\n"
00228          ;
00229       return NULL;
00230    case CLI_GENERATE:
00231       return NULL;
00232    default:
00233       break;
00234    }
00235 
00236    if (a->argc != 3) {
00237       return CLI_SHOWUSAGE;
00238    }
00239 
00240    crypted = ast_crypt_encrypt(a->argv[2]);
00241    if (!crypted) {
00242       ast_cli(a->fd, "Failed to encrypt password\n");
00243       return CLI_FAILURE;
00244    }
00245 
00246    ast_cli(a->fd,
00247       "; Copy the following two lines into ari.conf\n");
00248    ast_cli(a->fd, "password_format = crypt\n");
00249    ast_cli(a->fd, "password = %s\n", crypted);
00250 
00251    return CLI_SUCCESS;
00252 }

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

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

References ao2_cleanup, ao2_container_count(), ast_cli_args::argc, ast_ari_config_get(), ast_cli(), AST_CLI_YESNO, AST_JSON_COMPACT, AST_JSON_PRETTY, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, RAII_VAR, and ast_cli_entry::usage.

00034 {
00035    RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
00036 
00037    switch (cmd) {
00038    case CLI_INIT:
00039       e->command = "ari show status";
00040       e->usage =
00041          "Usage: ari show status\n"
00042          "       Shows all ARI settings\n";
00043       return NULL;
00044    case CLI_GENERATE:
00045       return NULL;
00046    default:
00047       break;
00048    }
00049 
00050    if (a->argc != 3) {
00051       return CLI_SHOWUSAGE;
00052    }
00053 
00054    conf = ast_ari_config_get();
00055 
00056    if (!conf) {
00057       ast_cli(a->fd, "Error getting ARI configuration\n");
00058       return CLI_FAILURE;
00059    }
00060 
00061    ast_cli(a->fd, "ARI Status:\n");
00062    ast_cli(a->fd, "Enabled: %s\n", AST_CLI_YESNO(conf->general->enabled));
00063    ast_cli(a->fd, "Output format: ");
00064    switch (conf->general->format) {
00065    case AST_JSON_COMPACT:
00066       ast_cli(a->fd, "compact");
00067       break;
00068    case AST_JSON_PRETTY:
00069       ast_cli(a->fd, "pretty");
00070       break;
00071    }
00072    ast_cli(a->fd, "\n");
00073    ast_cli(a->fd, "Auth realm: %s\n", conf->general->auth_realm);
00074    ast_cli(a->fd, "Allowed Origins: %s\n", conf->general->allowed_origins);
00075    ast_cli(a->fd, "User count: %d\n", ao2_container_count(conf->users));
00076    return CLI_SUCCESS;
00077 }

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

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

References ao2_cleanup, ao2_find, ast_cli_args::argc, ast_cli_args::argv, 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(), ast_cli_args::fd, NULL, OBJ_KEY, RAII_VAR, and ast_cli_entry::usage.

00175 {
00176    RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
00177    RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup);
00178 
00179    switch (cmd) {
00180    case CLI_INIT:
00181       e->command = "ari show user";
00182       e->usage =
00183          "Usage: ari show user <username>\n"
00184          "       Shows a specific ARI user\n";
00185       return NULL;
00186    case CLI_GENERATE:
00187       return complete_ari_show_user(a);
00188    default:
00189       break;
00190    }
00191 
00192    if (a->argc != 4) {
00193       return CLI_SHOWUSAGE;
00194    }
00195 
00196    conf = ast_ari_config_get();
00197 
00198    if (!conf) {
00199       ast_cli(a->fd, "Error getting ARI configuration\n");
00200       return CLI_FAILURE;
00201    }
00202 
00203    user = ao2_find(conf->users, a->argv[3], OBJ_KEY);
00204    if (!user) {
00205       ast_cli(a->fd, "User '%s' not found\n", a->argv[3]);
00206       return CLI_SUCCESS;
00207    }
00208 
00209    ast_cli(a->fd, "Username: %s\n", user->username);
00210    ast_cli(a->fd, "Read only?: %s\n", AST_CLI_YESNO(user->read_only));
00211 
00212    return CLI_SUCCESS;
00213 }

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

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

References ao2_callback, ao2_cleanup, ast_cli_args::argc, ast_ari_config_get(), ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, OBJ_NODATA, RAII_VAR, show_users_cb(), and ast_cli_entry::usage.

00092 {
00093    RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
00094 
00095    switch (cmd) {
00096    case CLI_INIT:
00097       e->command = "ari show users";
00098       e->usage =
00099          "Usage: ari show users\n"
00100          "       Shows all ARI users\n";
00101       return NULL;
00102    case CLI_GENERATE:
00103       return NULL;
00104    default:
00105       break;
00106    }
00107 
00108    if (a->argc != 3) {
00109       return CLI_SHOWUSAGE;
00110    }
00111 
00112    conf = ast_ari_config_get();
00113    if (!conf) {
00114       ast_cli(a->fd, "Error getting ARI configuration\n");
00115       return CLI_FAILURE;
00116    }
00117 
00118    ast_cli(a->fd, "r/o?  Username\n");
00119    ast_cli(a->fd, "----  --------\n");
00120 
00121    ao2_callback(conf->users, OBJ_NODATA, show_users_cb, a);
00122 
00123    return CLI_SUCCESS;
00124 }

int ast_ari_cli_register ( void   ) 

Register CLI commands for ARI.

Returns:
0 on success.

Non-zero on error.

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

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by load_module().

00261                                {
00262    return ast_cli_register_multiple(cli_ari, ARRAY_LEN(cli_ari));
00263 }

void ast_ari_cli_unregister ( void   ) 

Unregister CLI commands for ARI.

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

References ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by unload_module().

static char* complete_ari_show_user ( struct ast_cli_args a  )  [static]

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

References complete_ari_user(), NULL, and ast_cli_args::pos.

Referenced by ari_show_user().

00166 {
00167    if (a->pos == 3) {
00168       return complete_ari_user(a);
00169    }
00170 
00171    return NULL;
00172 }

static char* complete_ari_user ( struct ast_cli_args a  )  [static]

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

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

Referenced by complete_ari_show_user().

00144 {
00145    RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
00146    RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup);
00147 
00148    struct user_complete search = {
00149       .state = a->n,
00150    };
00151 
00152    conf = ast_ari_config_get();
00153    if (!conf) {
00154       ast_cli(a->fd, "Error getting ARI configuration\n");
00155       return CLI_FAILURE;
00156    }
00157 
00158    user = ao2_callback_data(conf->users,
00159       ast_strlen_zero(a->word) ? 0 : OBJ_PARTIAL_KEY,
00160       complete_ari_user_search, (char*)a->word, &search);
00161 
00162    return user ? ast_strdup(user->username) : NULL;
00163 }

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

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

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

Referenced by complete_ari_user().

00134 {
00135    struct user_complete *search = data;
00136 
00137    if (++search->which > search->state) {
00138       return CMP_MATCH;
00139    }
00140    return 0;
00141 }

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

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

References a, ast_cli(), AST_CLI_YESNO, ast_cli_args::fd, ast_ari_conf_user::read_only, and ast_ari_conf_user::username.

Referenced by ari_show_users().

00080 {
00081    struct ast_ari_conf_user *user = obj;
00082    struct ast_cli_args *a = arg;
00083 
00084    ast_cli(a->fd, "%-4s  %s\n",
00085       AST_CLI_YESNO(user->read_only),
00086       user->username);
00087    return 0;
00088 }


Variable Documentation

struct ast_cli_entry cli_ari[] [static]

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


Generated on Thu Apr 16 06:30:13 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6