[asterisk-commits] file: branch file/stasis_peerevent r390424 - /team/file/stasis_peerevent/res/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 4 12:18:50 CDT 2013


Author: file
Date: Tue Jun  4 12:18:49 2013
New Revision: 390424

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390424
Log:
Add progress for endpoint state. An observer now responds to contact changes and determines the new state for any endpoint impacted.

Modified:
    team/file/stasis_peerevent/res/res_sip/sip_configuration.c

Modified: team/file/stasis_peerevent/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/res/res_sip/sip_configuration.c?view=diff&rev=390424&r1=390423&r2=390424
==============================================================================
--- team/file/stasis_peerevent/res/res_sip/sip_configuration.c (original)
+++ team/file/stasis_peerevent/res/res_sip/sip_configuration.c Tue Jun  4 12:18:49 2013
@@ -53,6 +53,42 @@
 
 	return !strcmp(ast_endpoint_get_resource(persistent1->endpoint), id) ? CMP_MATCH | CMP_STOP : 0;
 }
+
+/*! \brief Callback function for changing the state of an endpoint */
+static int persistent_endpoint_update_state(void *obj, void *arg, int flags)
+{
+	struct sip_persistent_endpoint *persistent = obj;
+	char *aor = arg;
+	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+
+	if (!ast_strlen_zero(aor) && !strstr(persistent->aors, aor)) {
+		return 0;
+	}
+
+	if ((contact = ast_sip_location_retrieve_contact_from_aor_list(persistent->aors))) {
+		ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_ONLINE);
+	} else {
+		ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_OFFLINE);
+	}
+
+	return 0;
+}
+
+/*! \brief Function called when stuff relating to a contact happens (created/deleted) */
+static void persistent_endpoint_contact_observer(const void *object)
+{
+	char *id = ast_strdupa(ast_sorcery_object_get_id(object)), *aor = NULL;
+
+	aor = strsep(&id, ";@");
+
+	ao2_callback(persistent_endpoints, OBJ_NODATA, persistent_endpoint_update_state, aor);
+}
+
+/*! \brief Observer for contacts so state can be updated on respective endpoints */
+static struct ast_sorcery_observer state_contact_observer = {
+	.created = persistent_endpoint_contact_observer,
+	.deleted = persistent_endpoint_contact_observer,
+};
 
 static char *handle_cli_show_endpoints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -339,11 +375,16 @@
 			return NULL;
 		}
 
+		persistent->aors = ast_strdup(endpoint->aors);
+
+		if (ast_strlen_zero(persistent->aors)) {
+			ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_UNKNOWN);
+		} else {
+			persistent_endpoint_update_state(persistent, NULL, 0);
+		}
+
 		ao2_link_flags(persistent_endpoints, persistent, OBJ_NOLOCK);
 	}
-
-	ast_free(persistent->aors);
-	persistent->aors = ast_strdup(endpoint->aors);
 
 	ao2_ref(persistent->endpoint, +1);
 	return persistent->endpoint;
@@ -450,6 +491,8 @@
 		return -1;
 	}
 
+	ast_sorcery_observer_add(sip_sorcery, "contact", &state_contact_observer);
+
 	if (ast_sip_initialize_sorcery_domain_alias(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP domain aliases support with sorcery\n");
 		ast_sorcery_unref(sip_sorcery);




More information about the asterisk-commits mailing list