[Asterisk-code-review] res pjsip: Add AMI action 'PJSIPShowContacts' (asterisk[master])
sungtae kim
asteriskteam at digium.com
Sun Jan 14 12:36:47 CST 2018
sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/7960
Change subject: res_pjsip: Add AMI action 'PJSIPShowContacts'
......................................................................
res_pjsip: Add AMI action 'PJSIPShowContacts'
Add an AMI action which provides information on all
configured Contacts.
ASTERISK-27581
Change-Id: I2eed42c74bbc725fad26b8b33b1a5b3161950c73
---
M res/res_pjsip.c
M res/res_pjsip/pjsip_options.c
2 files changed, 188 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/60/7960/1
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 0311dfd..aad47af 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2362,6 +2362,79 @@
</syntax>
</managerEventInstance>
</managerEvent>
+ <managerEvent language="en_US" name="ContactList">
+ <managerEventInstance class="EVENT_FLAG_COMMAND">
+ <synopsis>Provide details about a contact section.</synopsis>
+ <syntax>
+ <parameter name="ObjectType">
+ <para>The object's type. This will always be 'contact'.</para>
+ </parameter>
+ <parameter name="ObjectName">
+ <para>The name of this object.</para>
+ </parameter>
+ <parameter name="ViaAddr">
+ <para>IP address of the last Via header in REGISTER request.
+ Will only appear in the event if available.</para>
+ </parameter>
+ <parameter name="ViaPort">
+ <para>Port number of the last Via header in REGISTER request.
+ Will only appear in the event if available.</para>
+ </parameter>
+ <parameter name="QualifyTimeout">
+ <para>The elapsed time in decimal seconds after which an OPTIONS
+ message is sent before the contact is considered unavailable.</para>
+ </parameter>
+ <parameter name="CallId">
+ <para>Content of the Call-ID header in REGISTER request.
+ Will only appear in the event if available.</para>
+ </parameter>
+ <parameter name="RegServer">
+ <para>Asterisk Server name.</para>
+ </parameter>
+ <parameter name="PruneOnBoot">
+ <para>If true delete the contact on Asterisk restart/boot.</para>
+ </parameter>
+ <parameter name="Path">
+ <para>The Path header received on the REGISTER.</para>
+ </parameter>
+ <parameter name="Endpoint">
+ <para>The name of the endpoint associated with this information.</para>
+ </parameter>
+ <parameter name="AuthenticateQualify">
+ <para>A boolean indicating whether a qualify should be authenticated.</para>
+ </parameter>
+ <parameter name="Uri">
+ <para>This contact's URI.</para>
+ </parameter>
+ <parameter name="QualifyFrequency">
+ <para>The interval in seconds at which the contact will be qualified.</para>
+ </parameter>
+ <parameter name="UserAgent">
+ <para>Content of the User-Agent header in REGISTER request</para>
+ </parameter>
+ <parameter name="ExpirationTime">
+ <para>Absolute time that this contact is no longer valid after</para>
+ </parameter>
+ <parameter name="OutboundProxy">
+ <para>The contact's outbound proxy.</para>
+ </parameter>
+ <parameter name="ID">
+ <para>The sorcery ID of the contact.</para>
+ </parameter>
+ <parameter name="Status">
+ <para>This contact's status.</para>
+ <enumlist>
+ <enum name="Reachable"/>
+ <enum name="Unreachable"/>
+ <enum name="NonQualified"/>
+ </enumlist>
+ </parameter>
+ <parameter name="RoundtripUsec">
+ <para>The round trip time in microseconds.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
<managerEvent language="en_US" name="ContactStatusDetail">
<managerEventInstance class="EVENT_FLAG_COMMAND">
<synopsis>Provide details about a contact's status.</synopsis>
@@ -2574,6 +2647,33 @@
</managerEvent>
</responses>
</manager>
+ <manager name="PJSIPShowContacts" language="en_US">
+ <synopsis>
+ Lists PJSIP Contacts.
+ </synopsis>
+ <syntax />
+ <description>
+ <para>Provides a listing of all Contacts. For each Contact an <literal>ContactList
+ </literal> event is raised that contains relevant attributes and status information.
+ Once all contacts have been listed an <literal>ContactListComplete</literal> event
+ is issued.
+ </para>
+ </description>
+ <responses>
+ <list-elements>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='ContactList'])" />
+ </list-elements>
+ <managerEvent language="en_US" name="ContactListComplete">
+ <managerEventInstance class="EVENT_FLAG_COMMAND">
+ <synopsis>Provide final information about a contact list.</synopsis>
+ <syntax>
+ <parameter name="EventList"/>
+ <parameter name="ListItems"/>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ </responses>
+ </manager>
***/
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 9d7402b..56a80af 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -929,6 +929,90 @@
return 0;
}
+static struct ao2_container *cli_get_contacts(void)
+{
+ struct ao2_container *contacts;
+
+ contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact",
+ AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+
+ return contacts;
+}
+
+static int sip_contact_to_ami(const struct ast_sip_contact *contact,
+ struct ast_str **buf)
+{
+ return ast_sip_sorcery_object_to_ami(contact, buf);
+}
+
+static int format_ami_contactlist_handler(void *obj, void *arg, int flags)
+{
+ struct ast_sip_contact *contact = obj;
+ struct ast_sip_ami *ami = arg;
+ struct ast_str *buf;
+ struct ast_sip_contact_status *status;
+
+ buf = ast_sip_create_ami_event("ContactList", ami);
+
+ if (!buf) {
+ return CMP_STOP;
+ }
+
+ if (sip_contact_to_ami(contact, &buf)) {
+ return CMP_STOP;
+ }
+
+ /* Add extra info */
+ ast_str_append(&buf, 0, "ID: %s\r\n", ast_sorcery_object_get_id(contact));
+ status = ast_sorcery_retrieve_by_id(
+ ast_sip_get_sorcery(), CONTACT_STATUS,
+ ast_sorcery_object_get_id(contact));
+ ast_str_append(&buf, 0, "Status: %s\r\n", ast_sip_get_contact_status_label(status ? status->status : UNKNOWN));
+ if (!status || status->status == UNKNOWN) {
+ ast_str_append(&buf, 0, "RoundtripUsec: N/A\r\n");
+ } else {
+ ast_str_append(&buf, 0, "RoundtripUsec: %" PRId64 "\r\n", status->rtt);
+ }
+
+ astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+
+ ami->count++;
+
+ ast_free(buf);
+
+ return 0;
+}
+
+static int ami_show_contacts(struct mansession *s, const struct message *m)
+{
+ struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
+ struct ao2_container *contacts;
+
+ contacts = cli_get_contacts();
+ if (!contacts) {
+ astman_send_error(s, m, "Could not get Contacts\n");
+ return 0;
+ }
+
+ if (!ao2_container_count(contacts)) {
+ astman_send_error(s, m, "No Contacts found\n");
+ ao2_ref(contacts, -1);
+ return 0;
+ }
+
+ astman_send_listack(s, m, "A listing of Contacts follows, presented as ContactList events",
+ "start");
+
+ ao2_callback(contacts, OBJ_NODATA, format_ami_contactlist_handler, &ami);
+
+ astman_send_list_complete_start(s, m, "ContactListComplete", ami.count);
+ astman_send_list_complete_end(s);
+
+ ao2_ref(contacts, -1);
+
+ return 0;
+}
+
static int ami_sip_qualify(struct mansession *s, const struct message *m)
{
const char *endpoint_name = astman_get_header(m, "Endpoint");
@@ -1481,6 +1565,10 @@
ast_manager_register_xml("PJSIPQualify", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, ami_sip_qualify);
ast_cli_register_multiple(cli_options, ARRAY_LEN(cli_options));
+ if (ast_manager_register_xml("PJSIPShowContacts", EVENT_FLAG_SYSTEM, ami_show_contacts)) {
+ return -1;
+ }
+
update_all_unqualified_endpoints();
qualify_and_schedule_all();
--
To view, visit https://gerrit.asterisk.org/7960
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2eed42c74bbc725fad26b8b33b1a5b3161950c73
Gerrit-Change-Number: 7960
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180114/70377761/attachment.html>
More information about the asterisk-code-review
mailing list