[asterisk-commits] kharwell: branch kharwell/pimp_sip_qualify r391753 - in /team/kharwell/pimp_s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 13 17:43:16 CDT 2013


Author: kharwell
Date: Thu Jun 13 17:43:15 2013
New Revision: 391753

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391753
Log:
addressed review issues

Modified:
    team/kharwell/pimp_sip_qualify/include/asterisk/res_sip.h
    team/kharwell/pimp_sip_qualify/res/res_sip/sip_configuration.c
    team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c

Modified: team/kharwell/pimp_sip_qualify/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_qualify/include/asterisk/res_sip.h?view=diff&rev=391753&r1=391752&r2=391753
==============================================================================
--- team/kharwell/pimp_sip_qualify/include/asterisk/res_sip.h (original)
+++ team/kharwell/pimp_sip_qualify/include/asterisk/res_sip.h Thu Jun 13 17:43:15 2013
@@ -142,6 +142,8 @@
 	/*! If true authenticate the qualify if needed */
 	int authenticate_qualify;
 };
+
+#define CONTACT_STATUS "contact_status"
 
 /*!
  * \brief Status type for a contact.

Modified: team/kharwell/pimp_sip_qualify/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_qualify/res/res_sip/sip_configuration.c?view=diff&rev=391753&r1=391752&r2=391753
==============================================================================
--- team/kharwell/pimp_sip_qualify/res/res_sip/sip_configuration.c (original)
+++ team/kharwell/pimp_sip_qualify/res/res_sip/sip_configuration.c Thu Jun 13 17:43:15 2013
@@ -57,8 +57,93 @@
 	return CLI_SUCCESS;
 }
 
+static int show_contact(void *obj, void *arg, int flags)
+{
+	struct ast_sip_contact *contact = obj;
+	struct ast_cli_args *a = arg;
+	RAII_VAR(struct ast_sip_contact_status *, status, ast_sorcery_retrieve_by_id(
+			 ast_sip_get_sorcery(), CONTACT_STATUS,
+			 ast_sorcery_object_get_id(contact)), ao2_cleanup);
+
+	ast_cli(a->fd, "\tContact %s:\n", contact->uri);
+
+	if (!status) {
+		ast_cli(a->fd, "\tStatus not found!\n");
+		return 0;
+	}
+
+	ast_cli(a->fd, "\t\tavailable = %s\n", status->status ? "yes" : "no");
+
+	if (status->status) {
+		ast_cli(a->fd, "\t\tRTT = %lld microseconds\n", (long long)status->rtt);
+	}
+
+	return 0;
+}
+
+static void show_endpoint(struct ast_sip_endpoint *endpoint, struct ast_cli_args *a)
+{
+	char *aor_name, *aors;
+
+	if (ast_strlen_zero(endpoint->aors)) {
+		return;
+	}
+
+	aors = ast_strdupa(endpoint->aors);
+
+	while ((aor_name = strsep(&aors, ","))) {
+		RAII_VAR(struct ast_sip_aor *, aor,
+			 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
+		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+
+		if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
+			continue;
+		}
+
+		ast_cli(a->fd, "AOR %s:\n", ast_sorcery_object_get_id(aor));
+		ao2_callback(contacts, OBJ_NODATA, show_contact, a);
+	}
+
+	return;
+}
+
+static char *cli_show_endpoint(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	const char *endpoint_name;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sip show endpoint";
+		e->usage =
+			"Usage: sip show endpoint <endpoint>\n"
+			"       Show the given SIP endpoint.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 4) {
+		return CLI_SHOWUSAGE;
+	}
+
+	endpoint_name = a->argv[3];
+
+	if (!(endpoint = ast_sorcery_retrieve_by_id(
+		      ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+		ast_cli(a->fd, "Unable to retrieve endpoint %s\n", endpoint_name);
+		return CLI_FAILURE;
+	}
+
+	ast_cli(a->fd, "Endpoint %s:\n", endpoint_name);
+	show_endpoint(endpoint, a);
+
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cli_commands[] = {
 	AST_CLI_DEFINE(handle_cli_show_endpoints, "Show SIP Endpoints"),
+	AST_CLI_DEFINE(cli_show_endpoint, "Show SIP Endpoint")
 };
 
 static int dtmf_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
@@ -505,4 +590,3 @@
 {
 	return sip_sorcery;
 }
-

Modified: team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c?view=diff&rev=391753&r1=391752&r2=391753
==============================================================================
--- team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c (original)
+++ team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c Thu Jun 13 17:43:15 2013
@@ -33,7 +33,6 @@
 #define DEFAULT_LANGUAGE "en"
 #define DEFAULT_ENCODING "text/plain"
 #define QUALIFIED_BUCKETS 211
-#define CONTACT_STATUS "contact_status"
 
 static int qualify_contact(struct ast_sip_contact *contact);
 
@@ -154,16 +153,6 @@
 
 /*!
  * \internal
- * \brief Send qualify request to the given contact.
- */
-static int on_contact(void *obj, void *arg, int flags)
-{
-	qualify_contact(obj);
-	return 0;
-}
-
-/*!
- * \internal
  * \brief For an endpoint try to match on a given contact.
  */
 static int on_endpoint(void *obj, void *arg, int flags)
@@ -171,7 +160,7 @@
 	struct ast_sip_endpoint *endpoint = obj;
 	char *aor_name, *aors;
 
-	if (ast_strlen_zero(endpoint->aors)) {
+	if (!arg || ast_strlen_zero(endpoint->aors)) {
 		return 0;
 	}
 
@@ -186,7 +175,7 @@
 			continue;
 		}
 
-		if (arg && ao2_find(contacts, arg, OBJ_NODATA | OBJ_POINTER)) {
+		if (ao2_find(contacts, arg, OBJ_NODATA | OBJ_POINTER)) {
 			return CMP_MATCH;
 		}
 	}
@@ -355,12 +344,6 @@
 {
 	struct sched_data *data = (struct sched_data *)obj;
 
-	if (!data->contact) {
-		/* contact is gone - so remove from scheduler */
-		ao2_cleanup(data);
-		return 0;
-	}
-
 	ao2_ref(data->contact, +1);
 	if (ast_sip_push_task(NULL, qualify_contact_task, data->contact)) {
 		ao2_ref(data->contact, -1);
@@ -387,7 +370,7 @@
 	if ((data->id = ast_sched_add_variable(
 		    sched, contact->qualify_frequency * 1000,
 		    qualify_contact_sched, data, 1)) < 0) {
-		
+
 		ao2_ref(data, -1);
 		ast_log(LOG_ERROR, "Unable to schedule qualify for contact %s\n",
 			contact->uri);
@@ -404,7 +387,7 @@
 static void unschedule_qualify(struct ast_sip_contact *contact)
 {
 	RAII_VAR(struct sched_data *, data, ao2_find(
-			 sched_qualifies, contact, OBJ_UNLINK | OBJ_NODATA), ao2_cleanup);
+			 sched_qualifies, contact, OBJ_UNLINK), ao2_cleanup);
 
 	if (!data) {
 		return;
@@ -595,13 +578,29 @@
 
 /*!
  * \internal
+ * \brief Send qualify request to the given contact.
+ */
+static int cli_on_contact(void *obj, void *arg, int flags)
+{
+	struct ast_sip_contact *contact = obj;
+	struct ast_cli_args *a = arg;
+	ast_cli(a->fd, " contact %s\n", contact->uri);
+	qualify_contact(contact);
+	return 0;
+}
+
+/*!
+ * \internal
  * \brief For an endpoint iterate over and qualify all aors/contacts
  */
-static void cli_qualify_contacts(struct ast_sip_endpoint *endpoint)
+static void cli_qualify_contacts(struct ast_cli_args *a, const char *endpoint_name,
+				 struct ast_sip_endpoint *endpoint)
 {
 	char *aor_name, *aors;
 
 	if (ast_strlen_zero(endpoint->aors)) {
+		ast_cli(a->fd, "Endpoint %s has no AoR's configured\n",
+			endpoint_name);
 		return;
 	}
 
@@ -616,7 +615,8 @@
 			continue;
 		}
 
-		ao2_callback(contacts, OBJ_NODATA, on_contact, NULL);
+		ast_cli(a->fd, "Sending qualify to endpoint %s", endpoint_name);
+		ao2_callback(contacts, OBJ_NODATA, cli_on_contact, a);
 	}
 }
 
@@ -644,101 +644,18 @@
 
 	if (!(endpoint = ast_sorcery_retrieve_by_id(
 		      ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
-		ast_log(LOG_ERROR, "Unable to retrieve endpoint %s\n", endpoint_name);
+		ast_cli(a->fd, "Unable to retrieve endpoint %s\n", endpoint_name);
 		return CLI_FAILURE;
 	}
 
 	/* send a qualify for all contacts registered with the endpoint */
-	cli_qualify_contacts(endpoint);
+	cli_qualify_contacts(a, endpoint_name, endpoint);
 
 	return CLI_SUCCESS;
 }
 
-static int show_contact(void *obj, void *arg, int flags)
-{
-	struct ast_sip_contact *contact = obj;
-	struct ast_cli_args *a = arg;
-	RAII_VAR(struct ast_sip_contact_status *, status,
-		 find_or_create_contact_status(contact), ao2_cleanup);
-
-	ast_cli(a->fd, "\tContact %s:\n", contact->uri);
-
-	if (!status) {
-		return 0;
-	}
-
-	ast_cli(a->fd, "\t\tavailable = %s\n", status->status ? "yes" : "no");
-
-	if (status->status) {
-		ast_cli(a->fd, "\t\tRTT = %lld microseconds\n", (long long)status->rtt);
-	}
-
-	return 0;
-}
-
-static void show_endpoint(struct ast_sip_endpoint *endpoint, struct ast_cli_args *a)
-{
-	char *aor_name, *aors;
-
-	if (ast_strlen_zero(endpoint->aors)) {
-		return;
-	}
-
-	aors = ast_strdupa(endpoint->aors);
-
-	while ((aor_name = strsep(&aors, ","))) {
-		RAII_VAR(struct ast_sip_aor *, aor,
-			 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
-		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
-
-		if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
-			continue;
-		}
-
-		ast_cli(a->fd, "AOR %s:\n", ast_sorcery_object_get_id(aor));
-		ao2_callback(contacts, OBJ_NODATA, show_contact, a);
-	}
-
-	return;
-}
-
-static char *cli_show_endpoint(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
-	const char *endpoint_name;
-
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "sip show endpoint";
-		e->usage =
-			"Usage: sip show endpoint <endpoint>\n"
-			"       Show the given SIP endpoint.\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	if (a->argc != 4) {
-		return CLI_SHOWUSAGE;
-	}
-
-	endpoint_name = a->argv[3];
-
-	if (!(endpoint = ast_sorcery_retrieve_by_id(
-		      ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
-		ast_log(LOG_ERROR, "Unable to retrieve endpoint %s\n", endpoint_name);
-		return CLI_FAILURE;
-	}
-
-	ast_cli(a->fd, "Endpoint %s:\n", endpoint_name);
-	show_endpoint(endpoint, a);
-
-	return CLI_SUCCESS;
-}
-
 static struct ast_cli_entry cli_options[] = {
-	AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a SIP endpoint"),
-	AST_CLI_DEFINE(cli_show_endpoint, "Show SIP Endpoint"),
+	AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a SIP endpoint")
 };
 
 static int sched_qualifies_hash_fn(const void *obj, int flags)




More information about the asterisk-commits mailing list