res_pjsip: AMI commands and events.

Created the following AMI commands and corresponding events for res_pjsip:

PJSIPShowEndpoints - Provides a listing of all pjsip endpoints and a few
                     select attributes on each.
  Events:
    EndpointList - for each endpoint a few attributes.
    EndpointlistComplete - after all endpoints have been listed.

PJSIPShowEndpoint - Provides a detail list of attributes for a specified
                    endpoint.
  Events:
    EndpointDetail - attributes on an endpoint.
    AorDetail - raised for each AOR on an endpoint.
    AuthDetail - raised for each associated inbound and outbound auth
    TransportDetail - transport attributes.
    IdentifyDetail - attributes for the identify object associated with
                     the endpoint.
    EndpointDetailComplete - last event raised after all detail events.

PJSIPShowRegistrationsInbound - Provides a detail listing of all inbound
                                registrations.
  Events:
    InboundRegistrationDetail - inbound registration attributes for each
                                registration.
    InboundRegistrationDetailComplete - raised after all detail records have
                                been listed.

PJSIPShowRegistrationsOutbound  - Provides a detail listing of all outbound
                                  registrations.
  Events:
    OutboundRegistrationDetail - outbound registration attributes for each
                                 registration.
    OutboundRegistrationDetailComplete - raised after all detail records
                                 have been listed.

PJSIPShowSubscriptionsInbound - A detail listing of all inbound subscriptions
                                and their attributes.
  Events:
    SubscriptionDetail - on each subscription detailed attributes
    SubscriptionDetailComplete - raised after all detail records have
                                 been listed.

PJSIPShowSubscriptionsOutbound - A detail listing of all outboundbound
                                subscriptions and their attributes.
  Events:
    SubscriptionDetail - on each subscription detailed attributes
    SubscriptionDetailComplete - raised after all detail records have
                                 been listed.

(issue ASTERISK-22609)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2959/
........

Merged revisions 403131 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403133 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin Harwell
2013-11-23 17:26:57 +00:00
parent 14a7452934
commit 05cbf8df9b
22 changed files with 1871 additions and 123 deletions

View File

@@ -32,6 +32,7 @@
#include "asterisk/taskprocessor.h"
#include "asterisk/cli.h"
#include "asterisk/stasis_system.h"
#include "res_pjsip/include/res_pjsip_private.h"
/*** DOCUMENTATION
<configInfo name="res_pjsip_outbound_registration" language="en_US">
@@ -129,6 +130,20 @@
</parameter>
</syntax>
</manager>
<manager name="PJSIPShowRegistrationsOutbound" language="en_US">
<synopsis>
Lists PJSIP outbound registrations.
</synopsis>
<syntax />
<description>
<para>
In response <literal>OutboundRegistrationDetail</literal> events showing configuration and status
information are raised for each outbound registration object. <literal>AuthDetail</literal>
events are raised for each associated auth object as well. Once all events are completed an
<literal>OutboundRegistrationDetailComplete</literal> is issued.
</para>
</description>
</manager>
***/
/*! \brief Amount of buffer time (in seconds) before expiration that we re-register at */
@@ -796,6 +811,12 @@ static int outbound_auth_handler(const struct aco_option *opt, struct ast_variab
return ast_sip_auth_array_init(&registration->outbound_auths, var->value);
}
static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **buf)
{
const struct sip_outbound_registration *registration = obj;
return ast_sip_auths_to_str(&registration->outbound_auths, buf);
}
static struct sip_outbound_registration *retrieve_registration(const char *registration_name)
{
return ast_sorcery_retrieve_by_id(
@@ -937,6 +958,85 @@ static struct ast_cli_entry cli_outbound_registration[] = {
AST_CLI_DEFINE(cli_unregister, "Send a REGISTER request to an outbound registration target with a expiration of 0")
};
struct sip_ami_outbound {
struct ast_sip_ami *ami;
int registered;
int not_registered;
struct sip_outbound_registration *registration;
};
static int ami_outbound_registration_task(void *obj)
{
struct sip_ami_outbound *ami = obj;
RAII_VAR(struct ast_str *, buf,
ast_sip_create_ami_event("OutboundRegistrationDetail", ami->ami), ast_free);
if (!buf) {
return -1;
}
ast_sip_sorcery_object_to_ami(ami->registration, &buf);
if (ami->registration->state) {
pjsip_regc_info info;
if (ami->registration->state->client_state->status ==
SIP_REGISTRATION_REGISTERED) {
++ami->registered;
} else {
++ami->not_registered;
}
ast_str_append(&buf, 0, "Status: %s%s",
sip_outbound_registration_status_str[
ami->registration->state->client_state->status], "\r\n");
pjsip_regc_get_info(ami->registration->state->client_state->client, &info);
ast_str_append(&buf, 0, "NextReg: %d%s", info.next_reg, "\r\n");
}
astman_append(ami->ami->s, "%s\r\n", ast_str_buffer(buf));
return ast_sip_format_auths_ami(&ami->registration->outbound_auths, ami->ami);
}
static int ami_outbound_registration_detail(void *obj, void *arg, int flags)
{
struct sip_ami_outbound *ami = arg;
ami->registration = obj;
return ast_sip_push_task_synchronous(
NULL, ami_outbound_registration_task, ami);
}
static int ami_show_outbound_registrations(struct mansession *s,
const struct message *m)
{
struct ast_sip_ami ami = { s = s, m = m };
struct sip_ami_outbound ami_outbound = { .ami = &ami };
RAII_VAR(struct ao2_container *, regs, ast_sorcery_retrieve_by_fields(
ast_sip_get_sorcery(), "registration", AST_RETRIEVE_FLAG_MULTIPLE |
AST_RETRIEVE_FLAG_ALL, NULL), ao2_cleanup);
if (!regs) {
astman_send_error(s, m, "Unable to retreive "
"outbound registrations\n");
return -1;
}
astman_send_listack(s, m, "Following are Events for each Outbound "
"registration", "start");
ao2_callback(regs, OBJ_NODATA, ami_outbound_registration_detail, &ami_outbound);
astman_append(s,
"Event: OutboundRegistrationDetailComplete\r\n"
"EventList: Complete\r\n"
"Registered: %d\r\n"
"NotRegistered: %d\r\n\r\n",
ami_outbound.registered,
ami_outbound.not_registered);
return 0;
}
static int load_module(void)
{
ast_sorcery_apply_default(ast_sip_get_sorcery(), "registration", "config", "pjsip.conf,criteria=type=registration");
@@ -956,12 +1056,13 @@ static int load_module(void)
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "forbidden_retry_interval", "0", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, forbidden_retry_interval));
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "max_retries", "10", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, max_retries));
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "auth_rejection_permanent", "yes", OPT_BOOL_T, 1, FLDSET(struct sip_outbound_registration, auth_rejection_permanent));
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "registration", "outbound_auth", "", outbound_auth_handler, NULL, 0, 0);
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "registration", "outbound_auth", "", outbound_auth_handler, outbound_auths_to_str, 0, 0);
ast_sorcery_reload_object(ast_sip_get_sorcery(), "registration");
sip_outbound_registration_perform_all();
ast_cli_register_multiple(cli_outbound_registration, ARRAY_LEN(cli_outbound_registration));
ast_manager_register_xml("PJSIPUnregister", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, ami_unregister);
ast_manager_register_xml("PJSIPShowRegistrationsOutbound", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING,ami_show_outbound_registrations);
return AST_MODULE_LOAD_SUCCESS;
}
@@ -975,6 +1076,7 @@ static int reload_module(void)
static int unload_module(void)
{
ast_cli_unregister_multiple(cli_outbound_registration, ARRAY_LEN(cli_outbound_registration));
ast_manager_unregister("PJSIPShowRegistrationsOutbound");
ast_manager_unregister("PJSIPUnregister");
return 0;
}