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)


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@404480 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Matthew Jordan
2013-12-20 21:23:24 +00:00
parent 50027152f7
commit b6aeb1b254
15 changed files with 1088 additions and 213 deletions

View File

@@ -691,6 +691,7 @@ void ast_include_rename(struct ast_config *conf, const char *from_file, const ch
void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line);
int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line);
struct ast_variable *ast_variable_list_sort(struct ast_variable *start);
/*!
* \brief Update variable value within a config

View File

@@ -38,6 +38,9 @@
#include <pjlib.h>
/* Needed for ast_rtp_dtls_cfg struct */
#include "asterisk/rtp_engine.h"
/* Needed for ast_sip_for_each_channel_snapshot struct */
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_endpoints.h"
/* Forward declarations of PJSIP stuff */
struct pjsip_rx_data;
@@ -211,6 +214,17 @@ struct ast_sip_aor {
struct ao2_container *permanent_contacts;
};
/*!
* \brief Aor/Contact pair used for ast_sip_for_each_contact callback.
*/
struct ast_sip_aor_contact_pair {
SORCERY_OBJECT(details);
/*! Aor */
struct ast_sip_aor *aor;
/*! Contact */
struct ast_sip_contact *contact;
};
/*!
* \brief DTMF modes for SIP endpoints
*/
@@ -1549,13 +1563,6 @@ void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
#define ast_sip_mod_data_set(pool, mod_data, id, key, val) \
mod_data[id] = ast_sip_dict_set(pool, mod_data[id], key, val)
/*!
* \brief Function pointer for contact callbacks.
*/
typedef int (*on_contact_t)(const struct ast_sip_aor *aor,
const struct ast_sip_contact *contact,
int last, void *arg);
/*!
* \brief For every contact on an AOR call the given 'on_contact' handler.
*
@@ -1564,21 +1571,18 @@ typedef int (*on_contact_t)(const struct ast_sip_aor *aor,
* \param arg user data passed to handler
* \retval 0 Success, non-zero on failure
*/
int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
on_contact_t on_contact, void *arg);
int ast_sip_for_each_contact(struct ast_sip_aor *aor,
ao2_callback_fn on_contact, void *arg);
/*!
* \brief Handler used to convert a contact to a string.
*
* \param aor the aor containing a list of contacts to iterate
* \param contact the contact to convert
* \param last is this the last contact
* \param object the ast_sip_aor_contact_pair containing a list of contacts to iterate and the contact
* \param arg user data passed to handler
* \param flags
* \retval 0 Success, non-zero on failure
*/
int ast_sip_contact_to_str(const struct ast_sip_aor *aor,
const struct ast_sip_contact *contact,
int last, void *arg);
int ast_sip_contact_to_str(void *object, void *arg, int flags);
/*!
* \brief For every aor in the comma separated aors string call the
@@ -1699,4 +1703,47 @@ int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint,
int ast_sip_format_auths_ami(const struct ast_sip_auth_array *auths,
struct ast_sip_ami *ami);
/*!
* \brief Retrieve the endpoint snapshot for an endpoint
*
* \param endpoint The endpoint whose snapshot is to be retreieved.
* \retval The endpoint snapshot
*/
struct ast_endpoint_snapshot *ast_sip_get_endpoint_snapshot(
const struct ast_sip_endpoint *endpoint);
/*!
* \brief Retrieve the device state for an endpoint.
*
* \param endpoint The endpoint whose state is to be retrieved.
* \retval The device state.
*/
const char *ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint);
/*!
* \brief For every channel snapshot on an endpoint snapshot call the given
* 'on_channel_snapshot' handler.
*
* \param endpoint_snapshot snapshot of an endpoint
* \param on_channel_snapshot callback for each channel snapshot
* \param arg user data passed to handler
* \retval 0 Success, non-zero on failure
*/
int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot,
ao2_callback_fn on_channel_snapshot,
void *arg);
/*!
* \brief For every channel snapshot on an endpoint all the given
* 'on_channel_snapshot' handler.
*
* \param endpoint endpoint
* \param on_channel_snapshot callback for each channel snapshot
* \param arg user data passed to handler
* \retval 0 Success, non-zero on failure
*/
int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint,
ao2_callback_fn on_channel_snapshot,
void *arg);
#endif /* _RES_PJSIP_H */

View File

@@ -0,0 +1,95 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2013, Fairview 5 Engineering, LLC.
*
* George Joseph <george.joseph@fairview5.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
#ifndef RES_PJSIP_CLI_H_
#define RES_PJSIP_CLI_H_
#define CLI_HEADER_FILLER ".........................................................................................."
#define CLI_DETAIL_FILLER " "
#define CLI_MAX_WIDTH 90
#define CLI_LAST_TABSTOP 62
#define CLI_MAX_TITLE_NAME 8
#define CLI_INDENT_TO_SPACES(x) ((x * 2) + 1 + CLI_MAX_TITLE_NAME)
/*
* \brief CLI Formatter Context
*/
struct ast_sip_cli_context {
int peers_mon_online;
int peers_mon_offline;
int peers_unmon_offline;
int peers_unmon_online;
struct ast_str *output_buffer;
const struct ast_cli_args *a;
const struct ast_sip_endpoint *current_endpoint;
const struct ast_sip_auth *current_auth;
const struct ast_sip_aor *current_aor;
char *auth_direction;
unsigned int print_flags;
int indent_level;
unsigned show_details : 1;
unsigned recurse : 1;
unsigned show_details_only_level_0 : 1;
};
/*
* \brief CLI Formatter Registry Entry
*/
struct ast_sip_cli_formatter_entry {
const char *name;
ao2_callback_fn *print_header;
ao2_callback_fn *print_body;
struct ao2_container *(* get_container)(struct ast_sorcery *);
};
/*!
* \brief Registers a CLI formatter.
*
* \param name The name of the formatter, usually the sorcery object type.
* \param formatter An ao2_callback_fn that outputs the formatted data.
* \retval 0 Success, non-zero on failure
*/
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter);
/*!
* \brief Unregisters a CLI formatter.
*
* \param name The name of the formatter, usually the sorcery object type.
* \retval 0 Success, non-zero on failure
*/
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter);
/*!
* \brief Looks up a CLI formatter by type.
*
* \param name The name of the formatter, usually the sorcery object type.
* \retval Pointer to formatter entry structure
*/
struct ast_sip_cli_formatter_entry *ast_sip_lookup_cli_formatter(const char *name);
/*!
* \brief Prints a sorcery object's ast_variable list
*
* \param obj The sorcery object
* \param arg The ast_sip_cli_context.
* \retval 0 Success, non-zero on failure
*/
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags);
#endif /* RES_PJSIP_CLI_H_ */

View File

@@ -823,6 +823,12 @@ const char *ast_sorcery_object_get_extended(const void *object, const char *name
*/
int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value);
/*!
* \brief Sorcery object comparator based on id.
*/
int ast_sorcery_object_id_compare(const void *obj_left, const void *obj_right, int flags);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif