mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
res_pjsip: Add PJSIP CLI commands
Implements the following cli commands: pjsip list aors pjsip list auths pjsip list channels pjsip list contacts pjsip list endpoints pjsip show aor(s) pjsip show auth(s) pjsip show channels pjsip show endpoint(s) Also... Minor modifications made to the AMI command implementations to facilitate reuse. New function ast_variable_list_sort added to config.c and config.h to implement variable list sorting. (issue ASTERISK-22610) patches: pjsip_cli_v2.patch uploaded by george.joseph (License 6322) ........ Merged revisions 404480 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404507 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
#include "asterisk/res_pjsip.h"
|
||||
#include "asterisk/logger.h"
|
||||
#include "asterisk/sorcery.h"
|
||||
#include "asterisk/cli.h"
|
||||
#include "include/res_pjsip_private.h"
|
||||
#include "asterisk/res_pjsip_cli.h"
|
||||
|
||||
static void auth_destroy(void *obj)
|
||||
{
|
||||
@@ -197,6 +199,59 @@ static struct ast_sip_endpoint_formatter endpoint_auth_formatter = {
|
||||
.format_ami = format_ami_endpoint_auth
|
||||
};
|
||||
|
||||
static struct ao2_container *cli_get_auth_container(struct ast_sorcery *sip_sorcery)
|
||||
{
|
||||
return ast_sorcery_retrieve_by_fields(sip_sorcery, "auth",
|
||||
AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
|
||||
}
|
||||
|
||||
static int cli_print_auth_header(void *obj, void *arg, int flags) {
|
||||
struct ast_sip_cli_context *context = arg;
|
||||
int indent = CLI_INDENT_TO_SPACES(context->indent_level);
|
||||
int filler = CLI_MAX_WIDTH - indent - 20;
|
||||
|
||||
if (!context->output_buffer) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ast_str_append(&context->output_buffer, 0,
|
||||
"%*s: <AuthId/UserName%*.*s>\n", indent, "I/OAuth", filler, filler, CLI_HEADER_FILLER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cli_print_auth_body(void *obj, void *arg, int flags) {
|
||||
struct ast_sip_auth *auth = obj;
|
||||
struct ast_sip_cli_context *context = arg;
|
||||
char title[32];
|
||||
|
||||
context->current_auth = auth;
|
||||
|
||||
if (!context->output_buffer) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(title, 32, "%sAuth",context->auth_direction ? context->auth_direction : "");
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s: %s/%s\n",
|
||||
CLI_INDENT_TO_SPACES(context->indent_level), title,
|
||||
ast_sorcery_object_get_id(auth), auth->auth_user);
|
||||
|
||||
if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) {
|
||||
ast_str_append(&context->output_buffer, 0, "\n");
|
||||
ast_sip_cli_print_sorcery_objectset(auth, context, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ast_sip_cli_formatter_entry cli_auth_formatter = {
|
||||
.name = SIP_SORCERY_AUTH_TYPE,
|
||||
.print_header = cli_print_auth_header,
|
||||
.print_body = cli_print_auth_body,
|
||||
.get_container = cli_get_auth_container,
|
||||
};
|
||||
|
||||
/*! \brief Initialize sorcery with auth support */
|
||||
int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery)
|
||||
{
|
||||
@@ -222,5 +277,7 @@ int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery)
|
||||
"userpass", auth_type_handler, auth_type_to_str, 0, 0);
|
||||
|
||||
ast_sip_register_endpoint_formatter(&endpoint_auth_formatter);
|
||||
ast_sip_register_cli_formatter(&cli_auth_formatter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user