summaryrefslogtreecommitdiff
path: root/main/stasis_endpoints.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-05-21 16:21:01 -0600
committerGeorge Joseph <george.joseph@fairview5.com>2015-05-26 16:47:55 -0500
commitb8ac68382225e2c0227d4764eebd7fdcea93249f (patch)
treec2140246d0f701ccfc21c62f7d0183970a15cfdc /main/stasis_endpoints.c
parent3a8eb3c476a0968b82bf9fb5e2e924567661e35f (diff)
res_pjsip: Add AMI events for chan_pjsip contact lifecycle changes
Add a new ContactStatus AMI event. Publish the following status/state changes: Created Removed Reachable Unreachable Unknown Contact URI, new status/state, aor and endpoint names, and the last qualify rtt result are included in the event. ASTERISK-25114 #close Change-Id: Id25aae5f7122facba183273efb3e8f36c20fb61e Reported-by: George Joseph <george.joseph@fairview5.com> Tested-by: George Joseph <george.joseph@fairview5.com>
Diffstat (limited to 'main/stasis_endpoints.c')
-rw-r--r--main/stasis_endpoints.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/main/stasis_endpoints.c b/main/stasis_endpoints.c
index f19bb91fe..da6505355 100644
--- a/main/stasis_endpoints.c
+++ b/main/stasis_endpoints.c
@@ -71,6 +71,35 @@ ASTERISK_REGISTER_FILE()
</syntax>
</managerEventInstance>
</managerEvent>
+ <managerEvent language="en_US" name="ContactStatus">
+ <managerEventInstance class="EVENT_FLAG_SYSTEM">
+ <synopsis>Raised when the state of a contact changes.</synopsis>
+ <syntax>
+ <parameter name="URI">
+ <para>This contact's URI.</para>
+ </parameter>
+ <parameter name="ContactStatus">
+ <para>New status of the contact.</para>
+ <enumlist>
+ <enum name="Unknown"/>
+ <enum name="Unreachable"/>
+ <enum name="Reachable"/>
+ <enum name="Created"/>
+ <enum name="Removed"/>
+ </enumlist>
+ </parameter>
+ <parameter name="AOR">
+ <para>The name of the associated aor.</para>
+ </parameter>
+ <parameter name="EndpointName">
+ <para>The name of the associated endpoint.</para>
+ </parameter>
+ <parameter name="RoundtripUsec">
+ <para>The RTT measured during the last qualify.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
***/
static struct stasis_cp_all *endpoint_cache_all;
@@ -137,6 +166,46 @@ static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *m
ast_str_buffer(peerstatus_event_string));
}
+static struct ast_manager_event_blob *contactstatus_to_ami(struct stasis_message *msg);
+
+STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_contact_state_type,
+ .to_ami = contactstatus_to_ami,
+);
+
+static struct ast_manager_event_blob *contactstatus_to_ami(struct stasis_message *msg)
+{
+ struct ast_endpoint_blob *obj = stasis_message_data(msg);
+ RAII_VAR(struct ast_str *, contactstatus_event_string, ast_str_create(64), ast_free);
+ const char *value;
+
+ if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "uri")))) {
+ return NULL;
+ }
+ ast_str_append(&contactstatus_event_string, 0, "URI: %s\r\n", value);
+
+ if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "contact_status")))) {
+ return NULL;
+ }
+ ast_str_append(&contactstatus_event_string, 0, "ContactStatus: %s\r\n", value);
+
+ if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "aor")))) {
+ return NULL;
+ }
+ ast_str_append(&contactstatus_event_string, 0, "AOR: %s\r\n", value);
+
+ if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "endpoint_name")))) {
+ return NULL;
+ }
+ ast_str_append(&contactstatus_event_string, 0, "EndpointName: %s\r\n", value);
+
+ if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec")))) {
+ ast_str_append(&contactstatus_event_string, 0, "RoundtripUsec: %s\r\n", value);
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "ContactStatus",
+ "%s", ast_str_buffer(contactstatus_event_string));
+}
+
static void endpoint_blob_dtor(void *obj)
{
struct ast_endpoint_blob *event = obj;
@@ -294,6 +363,7 @@ static void endpoints_stasis_cleanup(void)
{
STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_snapshot_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_state_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_contact_state_type);
ao2_cleanup(endpoint_cache_all);
endpoint_cache_all = NULL;
@@ -312,6 +382,7 @@ int ast_endpoint_stasis_init(void)
res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_snapshot_type);
res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_state_type);
+ res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_contact_state_type);
return res;
}