[asterisk-commits] rmudgett: trunk r407573 - in /trunk: ./ include/asterisk/ res/ res/res_pjsip/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 6 11:55:48 CST 2014
Author: rmudgett
Date: Thu Feb 6 11:55:45 2014
New Revision: 407573
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407573
Log:
res_pjsip: Updates and adds more PJSIP CLI commands.
* Adds identify, transport, and registration support to the PJSIP CLI.
* Creates three additional callbacks, one for an iterator, one for a
comparator, and one for a container. This eliminates the link dependency
from higher level modules to lower level ones.
* Eliminates duplicate sorting in PJSIP CLI commands.
* Cleans up PJSIP CLI output formatting.
* Pushes CLI command registration down to the implementing source file.
* Adds several ast_sip_destroy_sorcery functions to complement existing
ast_sip_sorcery_initialize functions. The destroy functions unregister
PJSIP CLI commands and PJSIP CLI formatters.
Reported by: George Joseph
Review: https://reviewboard.asterisk.org/r/3104/
........
Merged revisions 407568 from http://svn.asterisk.org/svn/asterisk/branches/12
Modified:
trunk/ (props changed)
trunk/include/asterisk/res_pjsip.h
trunk/include/asterisk/res_pjsip_cli.h
trunk/res/res_pjsip/config_auth.c
trunk/res/res_pjsip/config_domain_aliases.c
trunk/res/res_pjsip/config_global.c
trunk/res/res_pjsip/config_transport.c
trunk/res/res_pjsip/include/res_pjsip_private.h
trunk/res/res_pjsip/location.c
trunk/res/res_pjsip/pjsip_cli.c
trunk/res/res_pjsip/pjsip_configuration.c
trunk/res/res_pjsip/pjsip_options.c
trunk/res/res_pjsip_endpoint_identifier_ip.c
trunk/res/res_pjsip_logger.c
trunk/res/res_pjsip_outbound_registration.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.
Modified: trunk/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip.h?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/include/asterisk/res_pjsip.h (original)
+++ trunk/include/asterisk/res_pjsip.h Thu Feb 6 11:55:45 2014
@@ -218,17 +218,6 @@
struct ao2_container *permanent_contacts;
/*! Determines whether SIP Path headers are supported */
unsigned int support_path;
-};
-
-/*!
- * \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;
};
/*!
@@ -824,32 +813,42 @@
/*!
* \brief Initialize transport support on a sorcery instance
*
- * \param sorcery The sorcery instance
- *
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_initialize_sorcery_transport(struct ast_sorcery *sorcery);
-
-/*!
- * \brief Initialize qualify support on a sorcery instance
- *
- * \param sorcery The sorcery instance
+int ast_sip_initialize_sorcery_transport(void);
+
+/*!
+ * \brief Destroy transport support on a sorcery instance
*
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_initialize_sorcery_qualify(struct ast_sorcery *sorcery);
-
-/*!
- * \brief Initialize location support on a sorcery instance
- *
- * \param sorcery The sorcery instance
+int ast_sip_destroy_sorcery_transport(void);
+
+/*!
+ * \brief Initialize qualify support on a sorcery instance
*
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_initialize_sorcery_location(struct ast_sorcery *sorcery);
+int ast_sip_initialize_sorcery_qualify(void);
+
+/*!
+ * \brief Initialize location support on a sorcery instance
+ *
+ * \retval -1 failure
+ * \retval 0 success
+ */
+int ast_sip_initialize_sorcery_location(void);
+
+/*!
+ * \brief Destroy location support on a sorcery instance
+ *
+ * \retval -1 failure
+ * \retval 0 success
+ */
+int ast_sip_destroy_sorcery_location(void);
/*!
* \brief Retrieve a named AOR
@@ -936,22 +935,26 @@
/*!
* \brief Initialize domain aliases support on a sorcery instance
*
- * \param sorcery The sorcery instance
- *
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery);
+int ast_sip_initialize_sorcery_domain_alias(void);
/*!
* \brief Initialize authentication support on a sorcery instance
- *
- * \param sorcery The sorcery instance
*
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery);
+int ast_sip_initialize_sorcery_auth(void);
+
+/*!
+ * \brief Destroy authentication support on a sorcery instance
+ *
+ * \retval -1 failure
+ * \retval 0 success
+ */
+int ast_sip_destroy_sorcery_auth(void);
/*!
* \brief Callback called when an outbound request with authentication credentials is to be sent in dialog
@@ -1553,7 +1556,7 @@
int ast_sip_add_global_request_header(const char *name, const char *value, int replace);
int ast_sip_add_global_response_header(const char *name, const char *value, int replace);
-int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery);
+int ast_sip_initialize_sorcery_global(void);
/*!
* \brief Retrieves the value associated with the given key.
@@ -1618,7 +1621,7 @@
* \param arg user data passed to handler
* \retval 0 Success, non-zero on failure
*/
-int ast_sip_for_each_contact(struct ast_sip_aor *aor,
+int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
ao2_callback_fn on_contact, void *arg);
/*!
Modified: trunk/include/asterisk/res_pjsip_cli.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip_cli.h?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/include/asterisk/res_pjsip_cli.h (original)
+++ trunk/include/asterisk/res_pjsip_cli.h Thu Feb 6 11:55:45 2014
@@ -18,6 +18,8 @@
#ifndef RES_PJSIP_CLI_H_
#define RES_PJSIP_CLI_H_
+
+#include "asterisk/cli.h"
#define CLI_HEADER_FILLER ".........................................................................................."
#define CLI_DETAIL_FILLER " "
@@ -54,7 +56,9 @@
const char *name;
ao2_callback_fn *print_header;
ao2_callback_fn *print_body;
- struct ao2_container *(* get_container)(struct ast_sorcery *);
+ struct ao2_container *(* get_container)(void);
+ int (* iterator)(const void *container, ao2_callback_fn callback, void *args);
+ ao2_sort_fn *comparator;
};
/*!
@@ -91,5 +95,7 @@
*/
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags);
+char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+
#endif /* RES_PJSIP_CLI_H_ */
Modified: trunk/res/res_pjsip/config_auth.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_auth.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/config_auth.c (original)
+++ trunk/res/res_pjsip/config_auth.c Thu Feb 6 11:55:45 2014
@@ -199,13 +199,39 @@
.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) {
+static struct ao2_container *cli_get_auth_container(void)
+{
+ RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup);
+ RAII_VAR(struct ao2_container *, s_container, NULL, ao2_cleanup);
+
+ container = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "auth",
+ AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ if (!container) {
+ return NULL;
+ }
+
+ s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+ ast_sorcery_object_id_compare, NULL);
+ if (!s_container) {
+ return NULL;
+ }
+
+ if (ao2_container_dup(s_container, container, 0)) {
+ return NULL;
+ }
+ ao2_ref(s_container, +1);
+ return s_container;
+}
+
+static int cli_iterator(const void *container, ao2_callback_fn callback, void *args)
+{
+ const struct ast_sip_auth_vector *vector = container;
+
+ return ast_sip_for_each_auth(vector, callback, args);
+}
+
+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;
@@ -215,12 +241,14 @@
}
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) {
+ "%*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];
@@ -231,13 +259,15 @@
return -1;
}
- snprintf(title, 32, "%sAuth",context->auth_direction ? context->auth_direction : "");
+ snprintf(title, sizeof(title), "%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)) {
+ 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);
}
@@ -245,16 +275,35 @@
return 0;
}
-static struct ast_sip_cli_formatter_entry cli_auth_formatter = {
+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,
+ .iterator = cli_iterator,
+ .comparator = ast_sorcery_object_id_compare,
};
+static struct ast_cli_entry cli_commands[] = {
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Auths",
+ .command = "pjsip list auths",
+ .usage = "Usage: pjsip list auths\n"
+ " List the configured PJSIP Auths\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Auths",
+ .command = "pjsip show auths",
+ .usage = "Usage: pjsip show auths\n"
+ " Show the configured PJSIP Auths\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Auth",
+ .command = "pjsip show auth",
+ .usage = "Usage: pjsip show auth <id>\n"
+ " Show the configured PJSIP Auth\n"),
+};
+
/*! \brief Initialize sorcery with auth support */
-int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery)
-{
+int ast_sip_initialize_sorcery_auth(void)
+{
+ struct ast_sorcery *sorcery = ast_sip_get_sorcery();
+
ast_sorcery_apply_default(sorcery, SIP_SORCERY_AUTH_TYPE, "config", "pjsip.conf,criteria=type=auth");
if (ast_sorcery_object_register(sorcery, SIP_SORCERY_AUTH_TYPE, auth_alloc, NULL, auth_apply)) {
@@ -278,6 +327,14 @@
ast_sip_register_endpoint_formatter(&endpoint_auth_formatter);
ast_sip_register_cli_formatter(&cli_auth_formatter);
-
- return 0;
-}
+ ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
+
+ return 0;
+}
+
+int ast_sip_destroy_sorcery_auth(void)
+{
+ ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
+ ast_sip_unregister_cli_formatter(&cli_auth_formatter);
+ return 0;
+}
Modified: trunk/res/res_pjsip/config_domain_aliases.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_domain_aliases.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/config_domain_aliases.c (original)
+++ trunk/res/res_pjsip/config_domain_aliases.c Thu Feb 6 11:55:45 2014
@@ -48,8 +48,10 @@
}
/*! \brief Initialize sorcery with domain alias support */
-int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery)
+int ast_sip_initialize_sorcery_domain_alias(void)
{
+ struct ast_sorcery *sorcery = ast_sip_get_sorcery();
+
ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "pjsip.conf,criteria=type=domain_alias");
if (ast_sorcery_object_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, domain_alias_alloc, NULL, NULL)) {
Modified: trunk/res/res_pjsip/config_global.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_global.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/config_global.c (original)
+++ trunk/res/res_pjsip/config_global.c Thu Feb 6 11:55:45 2014
@@ -114,8 +114,10 @@
return res;
}
-int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
+int ast_sip_initialize_sorcery_global(void)
{
+ struct ast_sorcery *sorcery = ast_sip_get_sorcery();
+
snprintf(default_useragent, sizeof(default_useragent), "%s %s", DEFAULT_USERAGENT_PREFIX, ast_get_version());
ast_sorcery_apply_default(sorcery, "global", "config", "pjsip.conf,criteria=type=global");
Modified: trunk/res/res_pjsip/config_transport.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_transport.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/config_transport.c (original)
+++ trunk/res/res_pjsip/config_transport.c Thu Feb 6 11:55:45 2014
@@ -22,6 +22,7 @@
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_cli.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
#include "asterisk/sorcery.h"
@@ -276,8 +277,9 @@
{
struct ast_sip_transport *transport = obj;
pj_str_t buf;
-
- return (pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &transport->host) != PJ_SUCCESS) ? -1 : 0;
+ int rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &transport->host);
+
+ return rc != PJ_SUCCESS ? -1 : 0;
}
static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf)
@@ -446,9 +448,115 @@
return 0;
}
+static struct ao2_container *cli_get_container(void)
+{
+ RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup);
+ RAII_VAR(struct ao2_container *, s_container, NULL, ao2_cleanup);
+
+ container = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "transport",
+ AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ if (!container) {
+ return NULL;
+ }
+
+ s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+ ast_sorcery_object_id_compare, NULL);
+ if (!s_container) {
+ return NULL;
+ }
+
+ if (ao2_container_dup(s_container, container, 0)) {
+ return NULL;
+ }
+ ao2_ref(s_container, +1);
+ return s_container;
+}
+
+static int cli_iterator(const void *container, ao2_callback_fn callback, void *args)
+{
+ const struct ast_sip_endpoint *endpoint = container;
+ struct ast_sip_transport *transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
+ "transport", endpoint->transport);
+
+ if (!transport) {
+ return -1;
+ }
+ return callback(transport, args, 0);
+}
+
+static int cli_print_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 - 61;
+
+ if (!context->output_buffer) {
+ return -1;
+ }
+
+ ast_str_append(&context->output_buffer, 0,
+ "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
+ indent, "Transport", filler, filler, CLI_HEADER_FILLER);
+
+ return 0;
+}
+
+static int cli_print_body(void *obj, void *arg, int flags)
+{
+ struct ast_sip_transport *transport = obj;
+ struct ast_sip_cli_context *context = arg;
+ char hoststr[PJ_INET6_ADDRSTRLEN];
+
+ if (!context->output_buffer) {
+ return -1;
+ }
+
+ pj_sockaddr_print(&transport->host, hoststr, sizeof(hoststr), 3);
+
+ ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5x %5x %s\n",
+ CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
+ ast_sorcery_object_get_id(transport),
+ ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
+ transport->cos, transport->tos, hoststr);
+
+ 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(transport, context, 0);
+ }
+
+ return 0;
+}
+
+static struct ast_sip_cli_formatter_entry cli_formatter = {
+ .name = "transport",
+ .print_header = cli_print_header,
+ .print_body = cli_print_body,
+ .get_container = cli_get_container,
+ .iterator = cli_iterator,
+ .comparator = ast_sorcery_object_id_compare,
+};
+
+static struct ast_cli_entry cli_commands[] = {
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Transports",
+ .command = "pjsip list transports",
+ .usage = "Usage: pjsip list transports\n"
+ " List the configured PJSIP Transports\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transports",
+ .command = "pjsip show transports",
+ .usage = "Usage: pjsip show transports\n"
+ " Show the configured PJSIP Transport\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transport",
+ .command = "pjsip show transport",
+ .usage = "Usage: pjsip show transport <id>\n"
+ " Show the configured PJSIP Transport\n"),
+};
+
/*! \brief Initialize sorcery with transport support */
-int ast_sip_initialize_sorcery_transport(struct ast_sorcery *sorcery)
-{
+int ast_sip_initialize_sorcery_transport(void)
+{
+ struct ast_sorcery *sorcery = ast_sip_get_sorcery();
+
ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
if (ast_sorcery_object_register_no_reload(sorcery, "transport", transport_alloc, NULL, transport_apply)) {
@@ -477,5 +585,15 @@
ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
ast_sip_register_endpoint_formatter(&endpoint_transport_formatter);
- return 0;
-}
+ ast_sip_register_cli_formatter(&cli_formatter);
+ ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
+
+ return 0;
+}
+
+int ast_sip_destroy_sorcery_transport(void)
+{
+ ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
+ ast_sip_unregister_cli_formatter(&cli_formatter);
+ return 0;
+}
Modified: trunk/res/res_pjsip/include/res_pjsip_private.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/include/res_pjsip_private.h?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/include/res_pjsip_private.h (original)
+++ trunk/res/res_pjsip/include/res_pjsip_private.h Thu Feb 6 11:55:45 2014
@@ -99,7 +99,7 @@
/*!
* \brief Functions for initializing and destroying the CLI.
*/
-int ast_sip_initialize_cli(struct ast_sorcery *sip_sorcery);
+int ast_sip_initialize_cli(void);
void ast_sip_destroy_cli(void);
#endif /* RES_PJSIP_PRIVATE_H_ */
Modified: trunk/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/location.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/location.c (original)
+++ trunk/res/res_pjsip/location.c Thu Feb 6 11:55:45 2014
@@ -97,7 +97,7 @@
{
struct ao2_container *dest = arg;
- ao2_link_flags(dest, obj, OBJ_NOLOCK);
+ ao2_link(dest, obj);
return 0;
}
@@ -117,7 +117,7 @@
return NULL;
}
- contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL);
+ contact = ao2_callback(contacts, 0, contact_find_first, NULL);
return contact;
}
@@ -134,11 +134,11 @@
}
/* Prune any expired contacts and delete them, we do this first because static contacts can never expire */
- ao2_callback(contacts, OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, contact_expire, NULL);
+ ao2_callback(contacts, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, contact_expire, NULL);
/* Add any permanent contacts from the AOR */
if (aor->permanent_contacts) {
- ao2_callback(aor->permanent_contacts, OBJ_NOLOCK | OBJ_NODATA, contact_link_static, contacts);
+ ao2_callback(aor->permanent_contacts, OBJ_NODATA, contact_link_static, contacts);
}
return contacts;
@@ -269,7 +269,7 @@
}
ast_string_field_set(contact, uri, var->value);
- ao2_link_flags(aor->permanent_contacts, contact, OBJ_NOLOCK);
+ ao2_link(aor->permanent_contacts, contact);
return 0;
}
@@ -299,33 +299,7 @@
return 0;
}
-static void destroy_contact_pair(void *obj)
-{
- struct ast_sip_aor_contact_pair *pair = obj;
- ao2_cleanup(pair->aor);
- ao2_cleanup(pair->contact);
-}
-
-static struct ast_sip_aor_contact_pair *create_contact_pair(
- struct ast_sip_aor *aor, struct ast_sip_contact *contact)
-{
- struct ast_sip_aor_contact_pair *pair = ao2_alloc(
- sizeof(*pair), destroy_contact_pair);
-
- if (!pair) {
- return NULL;
- }
-
- pair->aor = aor;
- pair->contact = contact;
-
- ao2_ref(pair->aor, +1);
- ao2_ref(pair->contact, +1);
-
- return pair;
-}
-
-int ast_sip_for_each_contact(struct ast_sip_aor *aor,
+int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
ao2_callback_fn on_contact, void *arg)
{
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
@@ -340,10 +314,9 @@
i = ao2_iterator_init(contacts, 0);
while ((contact = ao2_iterator_next(&i))) {
int res;
- RAII_VAR(struct ast_sip_aor_contact_pair *,
- acp, create_contact_pair(aor, contact), ao2_cleanup);
-
- if (!acp || (res = on_contact(acp, arg, 0))) {
+
+ ast_sorcery_object_set_extended(contact, "@aor_id", ast_sorcery_object_get_id(aor));
+ if ((res = on_contact(contact, arg, 0))) {
ao2_iterator_destroy(&i);
return -1;
}
@@ -354,11 +327,11 @@
int ast_sip_contact_to_str(void *object, void *arg, int flags)
{
- struct ast_sip_aor_contact_pair *acp = object;
+ struct ast_sip_contact *contact = object;
struct ast_str **buf = arg;
ast_str_append(buf, 0, "%s/%s,",
- ast_sorcery_object_get_id(acp->aor), acp->contact->uri);
+ ast_sorcery_object_get_extended(contact, "aor_id"), contact->uri);
return 0;
}
@@ -413,15 +386,40 @@
.format_ami = format_ami_endpoint_aor
};
+static struct ao2_container *cli_get_aor_container(void)
+{
+ RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup);
+ RAII_VAR(struct ao2_container *, s_container, NULL, ao2_cleanup);
+
+ container = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "aor",
+ AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ if (!container) {
+ return NULL;
+ }
+
+ s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+ ast_sorcery_object_id_compare, NULL);
+ if (!s_container) {
+ return NULL;
+ }
+
+ if (ao2_container_dup(s_container, container, 0)) {
+ return NULL;
+ }
+ ao2_ref(s_container, +1);
+ return s_container;
+}
+
static int populate_contact_container(void *obj, void *arg, int flags)
{
- struct ast_sip_aor_contact_pair *acp = obj;
+ struct ast_sip_contact *contact = obj;
struct ao2_container *container = arg;
- ao2_link_flags(container, acp, OBJ_NOLOCK);
- return 0;
-}
-
-static int gather_aor_channels(void *obj, void *arg, int flags)
+
+ ao2_link(container, contact);
+ return 0;
+}
+
+static int gather_aor_contacts(void *obj, void *arg, int flags)
{
struct ast_sip_aor *aor = obj;
struct ao2_container *container = arg;
@@ -429,35 +427,51 @@
return 0;
}
-static struct ao2_container *cli_get_contact_container(struct ast_sorcery *sip_sorcery)
+static int cli_contact_compare(const void *left, const void *right, int flags)
+{
+ const struct ast_sip_contact *left_contact = left;
+ const struct ast_sip_contact *right_contact = right;
+ int rc;
+
+ if (!left_contact || !right_contact) {
+ return 0;
+ }
+ rc = strcmp(ast_sorcery_object_get_extended(left_contact, "aor_id"),
+ ast_sorcery_object_get_extended(right_contact, "aor_id"));
+ if (rc) {
+ return rc;
+ }
+ return strcmp(left_contact->uri, right_contact->uri);
+}
+
+static struct ao2_container *cli_get_contact_container(void)
{
RAII_VAR(struct ao2_container *, parent_container, NULL, ao2_cleanup);
- RAII_VAR(struct ao2_container *, s_parent_container, NULL, ao2_cleanup);
struct ao2_container *child_container;
- parent_container = ast_sorcery_retrieve_by_fields(sip_sorcery, "aor",
- AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ parent_container = cli_get_aor_container();
if (!parent_container) {
return NULL;
}
- s_parent_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, &ast_sorcery_object_id_compare, NULL);
- if (!s_parent_container) {
- return NULL;
- }
-
- ao2_container_dup(s_parent_container, parent_container, OBJ_ORDER_ASCENDING);
-
- child_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
+ child_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+ cli_contact_compare, NULL);
if (!child_container) {
return NULL;
}
- ao2_callback(s_parent_container, OBJ_NODATA, gather_aor_channels, child_container);
+ ao2_ref(child_container, +1);
+ ao2_callback(parent_container, OBJ_NODATA, gather_aor_contacts, child_container);
return child_container;
}
+static int cli_contact_iterator(const void *container, ao2_callback_fn callback, void *args)
+{
+ const struct ast_sip_aor *array = container;
+
+ return ast_sip_for_each_contact(array, callback, args);
+}
static int cli_print_contact_header(void *obj, void *arg, int flags)
{
@@ -477,28 +491,25 @@
static int cli_print_contact_body(void *obj, void *arg, int flags)
{
- struct ast_sip_aor_contact_pair *acp = obj;
+ struct ast_sip_contact *contact = obj;
struct ast_sip_cli_context *context = arg;
char *print_name = NULL;
int print_name_len;
int indent;
int flexwidth;
+ const char *aor_id = ast_sorcery_object_get_extended(contact, "aor_id");
RAII_VAR(struct ast_sip_contact_status *, status,
- ast_sorcery_retrieve_by_id( ast_sip_get_sorcery(), CONTACT_STATUS, ast_sorcery_object_get_id(acp->contact)),
+ ast_sorcery_retrieve_by_id( ast_sip_get_sorcery(), CONTACT_STATUS, ast_sorcery_object_get_id(contact)),
ao2_cleanup);
if (!context->output_buffer) {
return -1;
}
- print_name_len = strlen(ast_sorcery_object_get_id(acp->aor))
- + strlen(acp->contact->uri) + 2;
- if (!(print_name = alloca(print_name_len))) {
- return -1;
- }
- snprintf(print_name, print_name_len, "%s/%s",
- ast_sorcery_object_get_id(acp->aor), acp->contact->uri);
+ print_name_len = strlen(aor_id) + strlen(contact->uri) + 2;
+ print_name = ast_alloca(print_name_len);
+ snprintf(print_name, print_name_len, "%s/%s", aor_id, contact->uri);
indent = CLI_INDENT_TO_SPACES(context->indent_level);
flexwidth = CLI_LAST_TABSTOP - indent - 2;
@@ -514,10 +525,11 @@
return 0;
}
-static struct ao2_container *cli_get_aor_container(struct ast_sorcery *sip_sorcery)
-{
- return ast_sorcery_retrieve_by_fields(sip_sorcery, "aor",
- AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+static int cli_aor_iterator(const void *container, ao2_callback_fn callback, void *args)
+{
+ const char *aor_list = container;
+
+ return ast_sip_for_each_aor(aor_list, callback, args);
}
static int cli_print_aor_header(void *obj, void *arg, int flags)
@@ -538,7 +550,7 @@
if (context->recurse) {
context->indent_level++;
formatter_entry = ast_sip_lookup_cli_formatter("contact");
- if (formatter_entry) {
+ if (formatter_entry && formatter_entry->print_header) {
formatter_entry->print_header(NULL, context, 0);
}
context->indent_level--;
@@ -571,11 +583,17 @@
if (context->recurse) {
context->indent_level++;
+
formatter_entry = ast_sip_lookup_cli_formatter("contact");
- if (formatter_entry) {
- ast_sip_for_each_contact(aor, formatter_entry->print_body, context);
- }
+ if (formatter_entry && formatter_entry->print_body && formatter_entry->iterator) {
+ formatter_entry->iterator(aor, formatter_entry->print_body, context);
+ }
+
context->indent_level--;
+
+ if (context->indent_level == 0) {
+ ast_str_append(&context->output_buffer, 0, "\n");
+ }
}
if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) {
@@ -591,6 +609,8 @@
.print_header = cli_print_contact_header,
.print_body = cli_print_contact_body,
.get_container = cli_get_contact_container,
+ .iterator = cli_contact_iterator,
+ .comparator = cli_contact_compare,
};
static struct ast_sip_cli_formatter_entry cli_aor_formatter = {
@@ -598,11 +618,34 @@
.print_header = cli_print_aor_header,
.print_body = cli_print_aor_body,
.get_container = cli_get_aor_container,
+ .iterator = cli_aor_iterator,
+ .comparator = ast_sorcery_object_id_compare,
};
+static struct ast_cli_entry cli_commands[] = {
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Aors",
+ .command = "pjsip list aors",
+ .usage = "Usage: pjsip list aors\n"
+ " List the configured PJSIP Aors\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Aors",
+ .command = "pjsip show aors",
+ .usage = "Usage: pjsip show aors\n"
+ " Show the configured PJSIP Aors\n"),
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Aor",
+ .command = "pjsip show aor",
+ .usage = "Usage: pjsip show aor <id>\n"
+ " Show the configured PJSIP Aor\n"),
+
+ AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Contacts",
+ .command = "pjsip list contacts",
+ .usage = "Usage: pjsip list contacts\n"
+ " List the configured PJSIP contacts\n"),
+};
+
/*! \brief Initialize sorcery with location support */
-int ast_sip_initialize_sorcery_location(struct ast_sorcery *sorcery)
-{
+int ast_sip_initialize_sorcery_location(void)
+{
+ struct ast_sorcery *sorcery = ast_sip_get_sorcery();
ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar");
ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor");
@@ -635,6 +678,15 @@
ast_sip_register_endpoint_formatter(&endpoint_aor_formatter);
ast_sip_register_cli_formatter(&cli_contact_formatter);
ast_sip_register_cli_formatter(&cli_aor_formatter);
- return 0;
-}
-
+ ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
+ return 0;
+}
+
+int ast_sip_destroy_sorcery_location(void)
+{
+ ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
+ ast_sip_unregister_cli_formatter(&cli_contact_formatter);
+ ast_sip_unregister_cli_formatter(&cli_aor_formatter);
+ return 0;
+}
+
Modified: trunk/res/res_pjsip/pjsip_cli.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_cli.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/pjsip_cli.c (original)
+++ trunk/res/res_pjsip/pjsip_cli.c Thu Feb 6 11:55:45 2014
@@ -33,8 +33,6 @@
static struct ast_hashtab *formatter_registry;
-static struct ast_sorcery *sip_sorcery;
-
struct ast_sip_cli_formatter_entry *ast_sip_lookup_cli_formatter(const char *name)
{
struct ast_sip_cli_formatter_entry fake_entry = {
@@ -115,21 +113,20 @@
return result;
}
-static void dump_str_and_free(int fd, struct ast_str *buf) {
+static void dump_str_and_free(int fd, struct ast_str *buf)
+{
ast_cli(fd, "%s", ast_str_buffer(buf));
ast_free(buf);
}
-static char *cli_traverse_objects(struct ast_cli_entry *e, int cmd,
- struct ast_cli_args *a)
+char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup);
- RAII_VAR(struct ao2_container *, s_container, NULL, ao2_cleanup);
RAII_VAR(void *, object, NULL, ao2_cleanup);
int is_container = 0;
- const char *cmd1 = NULL;
- const char *cmd2 = NULL;
- const char *object_id = NULL;
+ const char *cmd1;
+ const char *cmd2;
+ const char *object_id;
char formatter_type[64];
struct ast_sip_cli_formatter_entry *formatter_entry;
@@ -154,9 +151,10 @@
object_id = a->argv[3];
if (!ast_ends_with(cmd2, "s")) {
- ast_copy_string(formatter_type, cmd2, strlen(cmd2)+1);
+ ast_copy_string(formatter_type, cmd2, sizeof(formatter_type));
is_container = 0;
} else {
+ /* Take the plural "s" off of the object name. */
ast_copy_string(formatter_type, cmd2, strlen(cmd2));
is_container = 1;
}
@@ -182,18 +180,21 @@
formatter_entry = ast_sip_lookup_cli_formatter(formatter_type);
if (!formatter_entry) {
- ast_log(LOG_ERROR, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
+ ast_log(LOG_ERROR, "No formatter registered for object type %s.\n",
+ formatter_type);
ast_free(context.output_buffer);
return CLI_FAILURE;
}
ast_str_append(&context.output_buffer, 0, "\n");
formatter_entry->print_header(NULL, &context, 0);
- ast_str_append(&context.output_buffer, 0, " =========================================================================================\n\n");
+ ast_str_append(&context.output_buffer, 0,
+ " =========================================================================================\n\n");
if (is_container || cmd == CLI_GENERATE) {
- container = formatter_entry->get_container(sip_sorcery);
+ container = formatter_entry->get_container();
if (!container) {
- ast_cli(a->fd, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
+ ast_cli(a->fd, "No container returned for object type %s.\n",
+ formatter_type);
ast_free(context.output_buffer);
return CLI_FAILURE;
}
@@ -210,22 +211,19 @@
ast_cli(a->fd, "No objects found.\n\n");
return CLI_SUCCESS;
}
-
- if (!strcmp(formatter_type, "channel") || !strcmp(formatter_type, "contact")) {
- s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
- } else {
- s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, &ast_sorcery_object_id_compare, NULL);
- }
-
- ao2_container_dup(s_container, container, OBJ_ORDER_ASCENDING);
-
- ao2_callback(s_container, OBJ_NODATA, formatter_entry->print_body, &context);
+ ao2_callback(container, OBJ_NODATA, formatter_entry->print_body, &context);
} else {
- if (!(object = ast_sorcery_retrieve_by_id(
- ast_sip_get_sorcery(), formatter_type, object_id))) {
+ if (ast_strlen_zero(object_id)) {
dump_str_and_free(a->fd, context.output_buffer);
- ast_cli(a->fd, "Unable to retrieve object %s\n", object_id);
+ ast_cli(a->fd, "No object specified.\n");
return CLI_FAILURE;
+ }
+ object = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), formatter_type,
+ object_id);
+ if (!object) {
+ dump_str_and_free(a->fd, context.output_buffer);
+ ast_cli(a->fd, "Unable to find object %s.\n\n", object_id);
+ return CLI_SUCCESS;
}
formatter_entry->print_body(object, &context, 0);
}
@@ -235,40 +233,8 @@
return CLI_SUCCESS;
}
-static struct ast_cli_entry cli_commands[] = {
- AST_CLI_DEFINE(cli_traverse_objects, "List PJSIP Channels", .command = "pjsip list channels",
- .usage = "Usage: pjsip list channels\n List the active PJSIP channels\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Channels", .command = "pjsip show channels",
- .usage = "Usage: pjsip show channels\n List(detailed) the active PJSIP channels\n"),
-
- AST_CLI_DEFINE(cli_traverse_objects, "List PJSIP Aors", .command = "pjsip list aors",
- .usage = "Usage: pjsip list aors\n List the configured PJSIP Aors\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Aors", .command = "pjsip show aors",
- .usage = "Usage: pjsip show aors\n Show the configured PJSIP Aors\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Aor", .command = "pjsip show aor",
- .usage = "Usage: pjsip show aor\n Show the configured PJSIP Aor\n"),
-
- AST_CLI_DEFINE(cli_traverse_objects, "List PJSIP Contacts", .command = "pjsip list contacts",
- .usage = "Usage: pjsip list contacts\n List the configured PJSIP contacts\n"),
-
- AST_CLI_DEFINE(cli_traverse_objects, "List PJSIP Endpoints", .command = "pjsip list endpoints",
- .usage = "Usage: pjsip list endpoints\n List the configured PJSIP endpoints\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Endpoints", .command = "pjsip show endpoints",
- .usage = "Usage: pjsip show endpoints\n List(detailed) the configured PJSIP endpoints\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Endpoint", .command = "pjsip show endpoint",
- .usage = "Usage: pjsip show endpoint <id>\n Show the configured PJSIP endpoint\n"),
-
- AST_CLI_DEFINE(cli_traverse_objects, "List PJSIP Auths", .command = "pjsip list auths",
- .usage = "Usage: pjsip list auths\n List the configured PJSIP Auths\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Auths", .command = "pjsip show auths",
- .usage = "Usage: pjsip show auths\n Show the configured PJSIP Auths\n"),
- AST_CLI_DEFINE(cli_traverse_objects, "Show PJSIP Auth", .command = "pjsip show auth",
- .usage = "Usage: pjsip show auth\n Show the configured PJSIP Auth\n"),
-
-};
-
-
-static int compare_formatters(const void *a, const void *b) {
+static int compare_formatters(const void *a, const void *b)
+{
const struct ast_sip_cli_formatter_entry *afe = a;
const struct ast_sip_cli_formatter_entry *bfe = b;
if (!afe || !bfe) {
@@ -278,18 +244,22 @@
return strcmp(afe->name, bfe->name);
}
-static unsigned int hash_formatters(const void *a) {
+static unsigned int hash_formatters(const void *a)
+{
const struct ast_sip_cli_formatter_entry *afe = a;
return ast_hashtab_hash_string(afe->name);
}
-int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter) {
+int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
+{
ast_hashtab_insert_safe(formatter_registry, formatter);
return 0;
}
-int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter) {
+int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
+{
struct ast_sip_cli_formatter_entry *entry = ast_hashtab_lookup(formatter_registry, formatter);
+
if (!entry) {
return -1;
}
@@ -297,7 +267,7 @@
return 0;
}
-int ast_sip_initialize_cli(struct ast_sorcery *sorcery)
+int ast_sip_initialize_cli(void)
{
formatter_registry = ast_hashtab_create(17, compare_formatters,
ast_hashtab_resize_java, ast_hashtab_newsize_java, hash_formatters, 0);
@@ -306,18 +276,11 @@
return -1;
}
- if (ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands))) {
- ast_log(LOG_ERROR, "Failed to register pjsip cli commands.\n");
- ast_hashtab_destroy(formatter_registry, ast_free_ptr);
- return -1;
- }
- sip_sorcery = sorcery;
return 0;
}
void ast_sip_destroy_cli(void)
{
- ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
if (formatter_registry) {
ast_hashtab_destroy(formatter_registry, ast_free_ptr);
}
Modified: trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=407573&r1=407572&r2=407573
==============================================================================
--- trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ trunk/res/res_pjsip/pjsip_configuration.c Thu Feb 6 11:55:45 2014
@@ -1168,48 +1168,83 @@
return 0;
}
-static int populate_channel_container(void *obj, void *arg, int flags) {
[... 799 lines stripped ...]
More information about the asterisk-commits
mailing list