chan_pjsip: Add the same details as PJSIPShowContacts to the CLI via 'pjsip show contact'
CLI 'pjsip show contact' does not show enough information. One must telnet to AMI or write a script to ask Asterisk for example what the User-Agent is on a Contact This feature adds the same details as PJSIPShowContacts to the CLI Resolves: #643
This commit is contained in:
parent
34196f8796
commit
4a64fa0a00
|
@ -42,14 +42,14 @@
|
|||
#include "include/cli_functions.h"
|
||||
|
||||
|
||||
static int cli_channel_iterate(void *endpoint, ao2_callback_fn callback, void *arg)
|
||||
static int cli_channel_iterate(void *endpoint, ao2_callback_fn callback, void *arg, int flags)
|
||||
{
|
||||
return ast_sip_for_each_channel(endpoint, callback, arg);
|
||||
return ast_sip_for_each_channel(endpoint, callback, arg, flags);
|
||||
}
|
||||
|
||||
static int cli_channelstats_iterate(void *endpoint, ao2_callback_fn callback, void *arg)
|
||||
static int cli_channelstats_iterate(void *endpoint, ao2_callback_fn callback, void *arg, int flags)
|
||||
{
|
||||
return ast_sip_for_each_channel(endpoint, callback, arg);
|
||||
return ast_sip_for_each_channel(endpoint, callback, arg, flags);
|
||||
}
|
||||
|
||||
static int cli_channel_sort(const void *obj, const void *arg, int flags)
|
||||
|
|
|
@ -2978,7 +2978,7 @@ void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
|
|||
* \retval 0 Success, non-zero on failure
|
||||
*/
|
||||
int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
|
||||
ao2_callback_fn on_contact, void *arg);
|
||||
ao2_callback_fn on_contact, void *arg, int flags);
|
||||
|
||||
/*!
|
||||
* \brief Handler used to convert a contact to a string.
|
||||
|
@ -3149,7 +3149,7 @@ const char *ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint);
|
|||
*/
|
||||
int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot,
|
||||
ao2_callback_fn on_channel_snapshot,
|
||||
void *arg);
|
||||
void *arg, int flags);
|
||||
|
||||
/*!
|
||||
* \brief For every channel snapshot on an endpoint all the given
|
||||
|
@ -3162,7 +3162,7 @@ int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoi
|
|||
*/
|
||||
int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint,
|
||||
ao2_callback_fn on_channel_snapshot,
|
||||
void *arg);
|
||||
void *arg, int flags);
|
||||
|
||||
enum ast_sip_supplement_priority {
|
||||
/*! Top priority. Supplements with this priority are those that need to run before any others */
|
||||
|
|
|
@ -63,7 +63,7 @@ struct ast_sip_cli_formatter_entry {
|
|||
/*! The function used to retrieve a container of all objects of this type. */
|
||||
struct ao2_container *(* get_container)(const char *regex);
|
||||
/*! The function used to iterate over a container of objects. */
|
||||
int (* iterate)(void *container, ao2_callback_fn callback, void *args);
|
||||
int (* iterate)(void *container, ao2_callback_fn callback, void *args, int flags);
|
||||
/*! The function used to retrieve a specific object from it's container. */
|
||||
void *(* retrieve_by_id)(const char *id);
|
||||
/*! The function used to retrieve an id string from an object. */
|
||||
|
|
|
@ -298,7 +298,7 @@ static struct ao2_container *cli_get_container(const char *regex)
|
|||
return s_container;
|
||||
}
|
||||
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
return ast_sip_for_each_auth(container, callback, args);
|
||||
}
|
||||
|
|
|
@ -1581,7 +1581,7 @@ static struct ao2_container *cli_get_container(const char *regex)
|
|||
return s_container;
|
||||
}
|
||||
|
||||
static int cli_iterate(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_iterate(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
const struct ast_sip_endpoint *endpoint = container;
|
||||
struct ast_sip_transport *transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
|
||||
|
|
|
@ -661,7 +661,7 @@ static int contacts_to_var_list(const void *obj, struct ast_variable **fields)
|
|||
{
|
||||
const struct ast_sip_aor *aor = obj;
|
||||
|
||||
ast_sip_for_each_contact(aor, contact_to_var_list, fields);
|
||||
ast_sip_for_each_contact(aor, contact_to_var_list, fields, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -720,7 +720,7 @@ static void contact_wrapper_destroy(void *obj)
|
|||
}
|
||||
|
||||
int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
|
||||
ao2_callback_fn on_contact, void *arg)
|
||||
ao2_callback_fn on_contact, void *arg, int flags)
|
||||
{
|
||||
struct ao2_container *contacts;
|
||||
struct ao2_iterator i;
|
||||
|
@ -758,7 +758,7 @@ int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
|
|||
wrapper->contact = contact;
|
||||
ao2_bump(wrapper->contact);
|
||||
|
||||
if ((res = on_contact(wrapper, arg, 0))) {
|
||||
if ((res = on_contact(wrapper, arg, flags))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -819,7 +819,7 @@ static int contacts_to_str(const void *obj, const intptr_t *args, char **buf)
|
|||
return -1;
|
||||
}
|
||||
|
||||
ast_sip_for_each_contact(aor, ast_sip_contact_to_str, &str);
|
||||
ast_sip_for_each_contact(aor, ast_sip_contact_to_str, &str, 0);
|
||||
ast_str_truncate(str, -1);
|
||||
|
||||
*buf = ast_strdup(ast_str_buffer(str));
|
||||
|
@ -913,7 +913,7 @@ static int cli_aor_gather_contacts(void *obj, void *arg, int flags)
|
|||
{
|
||||
struct ast_sip_aor *aor = obj;
|
||||
|
||||
return ast_sip_for_each_contact(aor, cli_contact_populate_container, arg);
|
||||
return ast_sip_for_each_contact(aor, cli_contact_populate_container, arg, 0);
|
||||
}
|
||||
|
||||
static const char *cli_contact_get_id(const void *obj)
|
||||
|
@ -976,9 +976,9 @@ static int cli_contact_compare(void *obj, void *arg, int flags)
|
|||
return cmp;
|
||||
}
|
||||
|
||||
static int cli_contact_iterate(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_contact_iterate(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
return ast_sip_for_each_contact(container, callback, args);
|
||||
return ast_sip_for_each_contact(container, callback, args, flags);
|
||||
}
|
||||
|
||||
static int cli_filter_contacts(void *obj, void *arg, int flags)
|
||||
|
@ -1113,8 +1113,10 @@ static int cli_contact_print_body(void *obj, void *arg, int flags)
|
|||
struct ast_sip_cli_context *context = arg;
|
||||
int indent;
|
||||
int flexwidth;
|
||||
int key_width;
|
||||
const char *contact_id = ast_sorcery_object_get_id(contact);
|
||||
const char *hash_start = contact_id + strlen(contact->aor) + 2;
|
||||
char secs[AST_TIME_T_LEN];
|
||||
struct ast_sip_contact_status *status;
|
||||
|
||||
ast_assert(contact->uri != NULL);
|
||||
|
@ -1123,8 +1125,8 @@ static int cli_contact_print_body(void *obj, void *arg, int flags)
|
|||
status = ast_sip_get_contact_status(contact);
|
||||
|
||||
indent = CLI_INDENT_TO_SPACES(context->indent_level);
|
||||
flexwidth = CLI_LAST_TABSTOP - indent - 9 - strlen(contact->aor) + 1;
|
||||
|
||||
flexwidth = CLI_LAST_TABSTOP - indent - strlen(contact->aor) + 1;
|
||||
ast_str_append(&context->output_buffer, 0, "%*s: %s/%-*.*s %-10.10s %-7.7s %11.3f\n",
|
||||
indent,
|
||||
"Contact",
|
||||
|
@ -1135,11 +1137,102 @@ static int cli_contact_print_body(void *obj, void *arg, int flags)
|
|||
ast_sip_get_contact_short_status_label(status ? status->status : UNKNOWN),
|
||||
(status && (status->status == AVAILABLE)) ? ((long long) status->rtt) / 1000.0 : NAN);
|
||||
|
||||
if (flags & AST_RETRIEVE_FLAG_ALL) { /* If we are showing list, no need do detailed */
|
||||
ao2_cleanup(status);
|
||||
return 0;
|
||||
}
|
||||
/* Detailed view or one entity start here */
|
||||
|
||||
indent = indent - 4;
|
||||
/* The key_width variable is set to define the minimum width for the first column in the output format. */
|
||||
key_width = 20; /* required to */
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"AuthenticateQualify:",
|
||||
contact->authenticate_qualify ? "yes" : "no");
|
||||
|
||||
if (!ast_strlen_zero(contact->call_id)) {
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %-41s\r\n",
|
||||
indent, " ", key_width,
|
||||
"CallID:", contact->call_id);
|
||||
}
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"Endpoint:", S_OR(contact->endpoint_name, ""));
|
||||
|
||||
ast_time_t_to_string(contact->expiration_time.tv_sec,
|
||||
secs, sizeof(secs));
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"ExpirationTime:", secs);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"OutboundProxy:", contact->outbound_proxy);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"Path:", contact->path);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"PruneOnBoot:", contact->prune_on_boot ? "yes" : "no");
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %u\r\n",
|
||||
indent, " ", key_width,
|
||||
"QualifyFrequency:", contact->qualify_frequency);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %.6f\r\n",
|
||||
indent, " ", key_width,
|
||||
"QualifyTimeout:", contact->qualify_timeout);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"RegServer:", contact->reg_server);
|
||||
|
||||
if (!status || status->status != AVAILABLE) {
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s N/A\r\n",
|
||||
indent, " ", key_width,
|
||||
"RoundtripUsec:");
|
||||
} else {
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %" PRId64 "\r\n",
|
||||
indent, " ", key_width,
|
||||
"RoundtripUsec:", status->rtt);
|
||||
}
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"Status:",
|
||||
ast_sip_get_contact_status_label(status ? status->status : UNKNOWN));
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"URI:", contact->uri);
|
||||
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"UserAgent:", contact->user_agent);
|
||||
|
||||
if (!ast_strlen_zero(contact->via_addr)) {
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %s\r\n",
|
||||
indent, " ", key_width,
|
||||
"ViaAddr:", contact->via_addr);
|
||||
|
||||
if (contact->via_port) {
|
||||
ast_str_append(&context->output_buffer, 0, "%*s%-*s %d\r\n",
|
||||
indent, " ", key_width,
|
||||
"ViaPort:", contact->via_port);
|
||||
}
|
||||
}
|
||||
|
||||
ao2_cleanup(status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cli_aor_iterate(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_aor_iterate(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
const char *aor_list = container;
|
||||
|
||||
|
@ -1210,7 +1303,7 @@ static int cli_aor_print_body(void *obj, void *arg, int flags)
|
|||
|
||||
formatter_entry = ast_sip_lookup_cli_formatter("contact");
|
||||
if (formatter_entry) {
|
||||
formatter_entry->iterate(aor, formatter_entry->print_body, context);
|
||||
formatter_entry->iterate(aor, formatter_entry->print_body, context, 2);/* simple view */
|
||||
ao2_ref(formatter_entry, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1657,7 +1657,7 @@ struct ast_endpoint_snapshot *ast_sip_get_endpoint_snapshot(
|
|||
|
||||
int ast_sip_for_each_channel_snapshot(
|
||||
const struct ast_endpoint_snapshot *endpoint_snapshot,
|
||||
ao2_callback_fn on_channel_snapshot, void *arg)
|
||||
ao2_callback_fn on_channel_snapshot, void *arg, int flags)
|
||||
{
|
||||
int num, num_channels = endpoint_snapshot->num_channels;
|
||||
|
||||
|
@ -1684,10 +1684,10 @@ int ast_sip_for_each_channel_snapshot(
|
|||
|
||||
int ast_sip_for_each_channel(
|
||||
const struct ast_sip_endpoint *endpoint,
|
||||
ao2_callback_fn on_channel_snapshot, void *arg)
|
||||
ao2_callback_fn on_channel_snapshot, void *arg, int flags)
|
||||
{
|
||||
RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, ast_sip_get_endpoint_snapshot(endpoint), ao2_cleanup);
|
||||
return ast_sip_for_each_channel_snapshot(endpoint_snapshot, on_channel_snapshot, arg);
|
||||
return ast_sip_for_each_channel_snapshot(endpoint_snapshot, on_channel_snapshot, arg, flags);
|
||||
}
|
||||
|
||||
static int active_channels_to_str_cb(void *object, void *arg, int flags)
|
||||
|
@ -1710,7 +1710,7 @@ static void active_channels_to_str(const struct ast_sip_endpoint *endpoint,
|
|||
}
|
||||
|
||||
ast_sip_for_each_channel_snapshot(endpoint_snapshot,
|
||||
active_channels_to_str_cb, str);
|
||||
active_channels_to_str_cb, str, 0);
|
||||
ast_str_truncate(*str, -1);
|
||||
}
|
||||
|
||||
|
@ -1767,7 +1767,7 @@ static int sip_endpoints_aors_ami(void *obj, void *arg, int flags)
|
|||
struct ast_str **buf = arg;
|
||||
|
||||
ast_str_append(buf, 0, "Contacts: ");
|
||||
ast_sip_for_each_contact(aor, ast_sip_contact_to_str, arg);
|
||||
ast_sip_for_each_contact(aor, ast_sip_contact_to_str, arg, flags);
|
||||
ast_str_append(buf, 0, "\r\n");
|
||||
|
||||
return 0;
|
||||
|
@ -1952,7 +1952,7 @@ static struct ao2_container *cli_endpoint_get_container(const char *regex)
|
|||
return s_container;
|
||||
}
|
||||
|
||||
static int cli_endpoint_iterate(void *obj, ao2_callback_fn callback, void *args)
|
||||
static int cli_endpoint_iterate(void *obj, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
ao2_callback(obj, OBJ_NODATA, callback, args);
|
||||
|
||||
|
@ -2002,7 +2002,7 @@ static void cli_endpoint_print_child_body(char *type, const void *obj, struct as
|
|||
|
||||
formatter_entry = ast_sip_lookup_cli_formatter(type);
|
||||
if (formatter_entry) {
|
||||
formatter_entry->iterate((void *)obj, formatter_entry->print_body, context);
|
||||
formatter_entry->iterate((void *)obj, formatter_entry->print_body, context, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1063,7 +1063,7 @@ static struct ao2_container *cli_unid_get_container(const char *regex)
|
|||
return s_container;
|
||||
}
|
||||
|
||||
static int cli_unid_iterate(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_unid_iterate(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
ao2_callback(container, 0, callback, args);
|
||||
|
||||
|
|
|
@ -2777,7 +2777,7 @@ static int format_contact_status_for_aor(void *obj, void *arg, int flags)
|
|||
{
|
||||
struct ast_sip_aor *aor = obj;
|
||||
|
||||
return ast_sip_for_each_contact(aor, ast_sip_format_contact_ami, arg);
|
||||
return ast_sip_for_each_contact(aor, ast_sip_format_contact_ami, arg, 0);
|
||||
}
|
||||
|
||||
static int format_ami_contact_status(const struct ast_sip_endpoint *endpoint,
|
||||
|
|
|
@ -672,7 +672,7 @@ struct ast_sip_endpoint_formatter endpoint_identify_formatter = {
|
|||
.format_ami = format_ami_endpoint_identify
|
||||
};
|
||||
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
const struct ast_sip_endpoint *endpoint = container;
|
||||
struct ao2_container *identifies;
|
||||
|
|
|
@ -2509,7 +2509,7 @@ static struct ao2_container *cli_get_container(const char *regex)
|
|||
return s_container;
|
||||
}
|
||||
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
|
||||
static int cli_iterator(void *container, ao2_callback_fn callback, void *args, int flags)
|
||||
{
|
||||
ao2_callback(container, OBJ_NODATA, callback, args);
|
||||
|
||||
|
|
|
@ -1242,7 +1242,7 @@ static int ami_registrations_aor(void *obj, void *arg, int flags)
|
|||
|
||||
ast_sip_sorcery_object_to_ami(aor, &buf);
|
||||
ast_str_append(&buf, 0, "Contacts: ");
|
||||
ast_sip_for_each_contact(aor, sip_contact_to_str, &buf);
|
||||
ast_sip_for_each_contact(aor, sip_contact_to_str, &buf, flags);
|
||||
ast_str_append(&buf, 0, "\r\n");
|
||||
|
||||
astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
|
||||
|
|
Loading…
Reference in New Issue