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/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@403131 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin Harwell
2013-11-23 17:14:22 +00:00
parent 22f800d14e
commit 24568ea6c9
22 changed files with 1871 additions and 123 deletions

View File

@@ -29,6 +29,8 @@
#include "asterisk/res_pjsip.h"
#include "asterisk/module.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "res_pjsip/include/res_pjsip_private.h"
/*** DOCUMENTATION
<configInfo name="res_pjsip_endpoint_identifier_ip" language="en_US">
@@ -164,6 +166,68 @@ static int ip_identify_match_handler(const struct aco_option *opt, struct ast_va
return error;
}
static int ip_identify_match_to_str(const void *obj, const intptr_t *args, char **buf)
{
RAII_VAR(struct ast_str *, str, ast_str_create(MAX_OBJECT_FIELD), ast_free);
const struct ip_identify_match *identify = obj;
ast_ha_join(identify->matches, &str);
*buf = ast_strdup(ast_str_buffer(str));
return 0;
}
static int sip_identify_to_ami(const struct ip_identify_match *identify,
struct ast_str **buf)
{
return ast_sip_sorcery_object_to_ami(identify, buf);
}
static int find_identify_by_endpoint(void *obj, void *arg, int flags)
{
struct ip_identify_match *identify = obj;
const char *endpoint_name = arg;
return strcmp(identify->endpoint_name, endpoint_name) ? 0 : CMP_MATCH | CMP_STOP;
}
static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint,
struct ast_sip_ami *ami)
{
RAII_VAR(struct ao2_container *, identifies, NULL, ao2_cleanup);
RAII_VAR(struct ip_identify_match *, identify, NULL, ao2_cleanup);
RAII_VAR(struct ast_str *, buf, NULL, ast_free);
if (!(identifies = ast_sorcery_retrieve_by_fields(
ast_sip_get_sorcery(), "identify", AST_RETRIEVE_FLAG_MULTIPLE |
AST_RETRIEVE_FLAG_ALL, NULL))) {
return -1;
}
if (!(identify = ao2_callback(identifies, OBJ_NOLOCK,
find_identify_by_endpoint,
(void*)ast_sorcery_object_get_id(endpoint)))) {
return 1;
}
if (!(buf = ast_sip_create_ami_event("IdentifyDetail", ami))) {
return -1;
}
if (sip_identify_to_ami(identify, &buf)) {
return -1;
}
ast_str_append(&buf, 0, "EndpointName: %s\r\n",
ast_sorcery_object_get_id(endpoint));
astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
return 0;
}
struct ast_sip_endpoint_formatter endpoint_identify_formatter = {
.format_ami = format_ami_endpoint_identify
};
static int load_module(void)
{
ast_sorcery_apply_default(ast_sip_get_sorcery(), "identify", "config", "pjsip.conf,criteria=type=identify");
@@ -174,10 +238,11 @@ static int load_module(void)
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "identify", "type", "", OPT_NOOP_T, 0, 0);
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "identify", "endpoint", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ip_identify_match, endpoint_name));
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "identify", "match", "", ip_identify_match_handler, NULL, 0, 0);
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "identify", "match", "", ip_identify_match_handler, ip_identify_match_to_str, 0, 0);
ast_sorcery_reload_object(ast_sip_get_sorcery(), "identify");
ast_sip_register_endpoint_identifier(&ip_identifier);
ast_sip_register_endpoint_formatter(&endpoint_identify_formatter);
return AST_MODULE_LOAD_SUCCESS;
}