[asterisk-commits] kharwell: branch kharwell/pimp_sip_qualify r390336 - /team/kharwell/pimp_sip_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 31 15:02:01 CDT 2013


Author: kharwell
Date: Fri May 31 15:02:00 2013
New Revision: 390336

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390336
Log:
added sip show endpoint cli command

Modified:
    team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c

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=390336&r1=390335&r2=390336
==============================================================================
--- team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c (original)
+++ team/kharwell/pimp_sip_qualify/res/res_sip/sip_options.c Fri May 31 15:02:00 2013
@@ -82,10 +82,9 @@
  */
 static struct contact_status *get_contact_status(const struct ast_sip_contact *contact)
 {
-	const char *id = ast_sorcery_object_get_id(contact);
-
 	struct contact_status *status = ast_sorcery_retrieve_by_id(
-		ast_sip_get_sorcery(), CONTACT_STATUS, id);
+		ast_sip_get_sorcery(), CONTACT_STATUS,
+		ast_sorcery_object_get_id(contact));
 
 	if (status) {
 		return status;
@@ -609,8 +608,91 @@
 	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 contact_status *, status,
+		 get_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"),
 };
 
 static int sched_qualifies_hash_fn(const void *obj, int flags)
@@ -733,8 +815,8 @@
 		return -1;
 	}
 
+	qualify_and_schedule_permanent();
 	ast_cli_register_multiple(cli_options, ARRAY_LEN(cli_options));
-	qualify_and_schedule_permanent();
 
 	return 0;
 }




More information about the asterisk-commits mailing list