[Asterisk-code-review] pjsip options: show/reload AOR qualify options using CLI (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Wed May 23 16:33:20 CDT 2018


Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/9047


Change subject: pjsip_options: show/reload AOR qualify options using CLI
......................................................................

pjsip_options: show/reload AOR qualify options using CLI

Currentrly pjsip_options code does not handle the situation when the
AOR qualify options were changed.

Also there is no way to find out what qualify options are using.

This patch add CLI commands to show and synchronize Aor qualify options:
pjsip show qualify endpoint <id>
    Show the current qualify options for all Aors on the PJSIP endpoint.
pjsip show qualify aor <id>
    Show the PJSIP Aor current qualify options.
pjsip reload qualify endpoint <id>
    Synchronize the qualify options for all Aors on the PJSIP endpoint.
pjsip reload qualify aor <id>
    Synchronize the PJSIP Aor qualify options.

ASTERISK-27872

Change-Id: I1746d10ef2b7954f2293f2e606cdd7428068c38c
---
M res/res_pjsip/pjsip_options.c
1 file changed, 188 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/47/9047/1

diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index d05d7bd..0ece477 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -2360,6 +2360,189 @@
 	return CLI_SUCCESS;
 }
 
+static char *cli_show_qualify_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;
+	char *aors;
+	char *aor_name;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pjsip show qualify endpoint";
+		e->usage =
+			"Usage: pjsip show qualify endpoint <id>\n"
+			"       Show the current qualify options for all Aors on the PJSIP endpoint.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 5) {
+		return CLI_SHOWUSAGE;
+	}
+
+	endpoint_name = a->argv[4];
+
+	endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+		endpoint_name);
+	if (!endpoint) {
+		ast_cli(a->fd, "Unable to retrieve endpoint %s\n", endpoint_name);
+		return CLI_FAILURE;
+	}
+
+	if (ast_strlen_zero(endpoint->aors)) {
+		ast_cli(a->fd, "No AORs configured for endpoint '%s'\n", endpoint_name);
+		return CLI_FAILURE;
+	}
+
+	aors = ast_strdupa(endpoint->aors);
+	while ((aor_name = ast_strip(strsep(&aors, ",")))) {
+		struct sip_options_aor *aor_options;
+
+		aor_options = ao2_find(sip_options_aors, aor_name, OBJ_SEARCH_KEY);
+		if (!aor_options) {
+			continue;
+		}
+
+		ast_cli(a->fd, " * AOR '%s' on endpoint '%s'\n", aor_name, endpoint_name);
+		ast_cli(a->fd, "  Qualify frequency    : %d sec\n", aor_options->qualify_frequency);
+		ast_cli(a->fd, "  Qualify timeout      : %d ms\n", (int)(aor_options->qualify_timeout / 1000));
+		ast_cli(a->fd, "  Authenticate qualify : %s\n", aor_options->authenticate_qualify?"yes":"no");
+		ast_cli(a->fd, "\n");
+		ao2_ref(aor_options, -1);
+	}
+
+	return CLI_SUCCESS;
+}
+
+static char *cli_show_qualify_aor(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct sip_options_aor *aor_options;
+	const char *aor_name;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pjsip show qualify aor";
+		e->usage =
+			"Usage: pjsip show qualify aor <id>\n"
+			"       Show the PJSIP Aor current qualify options.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 5) {
+		return CLI_SHOWUSAGE;
+	}
+
+	aor_name = a->argv[4];
+
+	aor_options = ao2_find(sip_options_aors, aor_name, OBJ_SEARCH_KEY);
+	if (!aor_options) {
+		ast_cli(a->fd, "Unable to retrieve aor '%s' qualify options\n", aor_name);
+		return CLI_FAILURE;
+	}
+
+	ast_cli(a->fd, " * AOR '%s'\n", aor_name);
+	ast_cli(a->fd, "  Qualify frequency    : %d sec\n", aor_options->qualify_frequency);
+	ast_cli(a->fd, "  Qualify timeout      : %d ms\n", (int)(aor_options->qualify_timeout / 1000));
+	ast_cli(a->fd, "  Authenticate qualify : %s\n", aor_options->authenticate_qualify?"yes":"no");
+	ao2_ref(aor_options, -1);
+
+	return CLI_SUCCESS;
+}
+
+static char *cli_reload_qualify_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;
+	char *aors;
+	char *aor_name;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pjsip reload qualify endpoint";
+		e->usage =
+			"Usage: pjsip reload qualify endpoint <id>\n"
+			"       Synchronize the qualify options for all Aors on the PJSIP endpoint.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 5) {
+		return CLI_SHOWUSAGE;
+	}
+
+	endpoint_name = a->argv[4];
+
+	endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+		endpoint_name);
+	if (!endpoint) {
+		ast_cli(a->fd, "Unable to retrieve endpoint %s\n", endpoint_name);
+		return CLI_FAILURE;
+	}
+
+	if (ast_strlen_zero(endpoint->aors)) {
+		ast_cli(a->fd, "No AORs configured for endpoint '%s'\n", endpoint_name);
+		return CLI_FAILURE;
+	}
+
+	aors = ast_strdupa(endpoint->aors);
+	while ((aor_name = ast_strip(strsep(&aors, ",")))) {
+		struct ast_sip_aor *aor;
+
+		aor = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor", aor_name);
+		if (!aor) {
+			continue;
+		}
+
+		ast_cli(a->fd, "Synchronizing AOR '%s' on endpoint '%s'\n", aor_name, endpoint_name);
+		ast_sip_push_task_wait_serializer(management_serializer,
+			sip_options_aor_observer_modified_task, aor);
+		ao2_ref(aor, -1);
+	}
+
+	return CLI_SUCCESS;
+}
+
+static char *cli_reload_qualify_aor(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_sip_aor *aor;
+	const char *aor_name;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pjsip reload qualify aor";
+		e->usage =
+			"Usage: pjsip reload qualify aor <id>\n"
+			"       Synchronize the PJSIP Aor qualify options.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 5) {
+		return CLI_SHOWUSAGE;
+	}
+
+	aor_name = a->argv[4];
+
+	aor = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor", aor_name);
+	if (!aor) {
+		ast_cli(a->fd, "Unable to retrieve aor '%s'\n", aor_name);
+		return CLI_FAILURE;
+	}
+
+	ast_cli(a->fd, "Synchronizing AOR '%s'\n", aor_name);
+	ast_sip_push_task_wait_serializer(management_serializer,
+		sip_options_aor_observer_modified_task, aor);
+	ao2_ref(aor, -1);
+
+	return CLI_SUCCESS;
+}
+
 static int ami_sip_qualify(struct mansession *s, const struct message *m)
 {
 	const char *endpoint_name = astman_get_header(m, "Endpoint");
@@ -2404,7 +2587,11 @@
 }
 
 static struct ast_cli_entry cli_options[] = {
-	AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a PJSIP endpoint")
+	AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a PJSIP endpoint"),
+	AST_CLI_DEFINE(cli_show_qualify_endpoint, "Show the current qualify options for all Aors on the PJSIP endpoint"),
+	AST_CLI_DEFINE(cli_show_qualify_aor, "Show the PJSIP Aor current qualify options"),
+	AST_CLI_DEFINE(cli_reload_qualify_endpoint, "Synchronize the qualify options for all Aors on the PJSIP endpoint"),
+	AST_CLI_DEFINE(cli_reload_qualify_aor, "Synchronize the PJSIP Aor qualify options"),
 };
 
 

-- 
To view, visit https://gerrit.asterisk.org/9047
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1746d10ef2b7954f2293f2e606cdd7428068c38c
Gerrit-Change-Number: 9047
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180523/5014a804/attachment-0001.html>


More information about the asterisk-code-review mailing list