Skip to content
Snippets Groups Projects
Commit 33519a0f authored by Iryna Antsyferova's avatar Iryna Antsyferova Committed by Iryna Antsyferova
Browse files

Implement "pjsip show srv_lookups" CLI command, REF 15305

parent 6c142872
No related branches found
No related tags found
No related merge requests found
Pipeline #179484 skipped
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <arpa/nameser.h> #include <arpa/nameser.h>
#include "asterisk/astobj2.h" #include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "asterisk/dns_core.h" #include "asterisk/dns_core.h"
#include "asterisk/dns_query_set.h" #include "asterisk/dns_query_set.h"
#include "asterisk/dns_srv.h" #include "asterisk/dns_srv.h"
...@@ -950,6 +951,63 @@ static void sip_check_transport(pj_pool_t *pool, pjsip_transport_type_e transpor ...@@ -950,6 +951,63 @@ static void sip_check_transport(pj_pool_t *pool, pjsip_transport_type_e transpor
} }
} }
static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char addr[PJ_INET6_ADDRSTRLEN + 10];
struct host_track_entry *host = NULL;
char *port = NULL;
int idx;
switch (cmd) {
case CLI_INIT:
e->command = "pjsip show srv_lookups";
e->usage = "Usage: pjsip show SRV DNS lookup records\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3) {
return CLI_SHOWUSAGE;
}
ast_cli(a->fd,
"<Host name......................................> "
"<IP address.................> <Port> <Transport.....> "
"<Weight> <Priority> <Expired at>\n"
"============================================================="
"============================================================="
"======\n");
AST_LIST_LOCK(&sip_resolve_track);
AST_LIST_TRAVERSE_SAFE_BEGIN(&sip_resolve_track, host, next) {
for (idx = 0; idx < host->addresses.count; ++idx) {
pj_sockaddr_print(&host->addresses.entry[idx].addr, addr, sizeof(addr), 3);
/* ipv6 is not supported */
if (!pj_gethostip(pj_AF_INET(), &host->addresses.entry[idx].addr)) {
if ((port = strstr(addr, ":"))) {
*port = '\0';
port++;
}
}
ast_cli(a->fd, "%-40.40s %-25.25s %-6s %-15.15s %8d %10d %-24s\n",
host->target.host, addr, host->target.port ? atoi(host->target.port) : (port ? port : 0),
pjsip_transport_get_type_desc(host->target.type),
host->addresses.entry[idx].weight,
host->addresses.entry[idx].priority,
ctime(&host->expiry));
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&sip_resolve_track);
return CLI_SUCCESS;
}
static struct ast_cli_entry cli_commands[] = {
AST_CLI_DEFINE(cli_show_tasks, "Show pjsip SRV DNS lookup records"),
};
/*! \brief External resolver implementation for PJSIP */ /*! \brief External resolver implementation for PJSIP */
static pjsip_ext_resolver ext_resolver = { static pjsip_ext_resolver ext_resolver = {
.resolve = sip_resolve, .resolve = sip_resolve,
...@@ -991,6 +1049,7 @@ void ast_sip_initialize_resolver(void) ...@@ -991,6 +1049,7 @@ void ast_sip_initialize_resolver(void)
{ {
/* Replace the existing PJSIP resolver with our own implementation */ /* Replace the existing PJSIP resolver with our own implementation */
ast_sip_push_task_wait_servant(NULL, sip_replace_resolver, NULL); ast_sip_push_task_wait_servant(NULL, sip_replace_resolver, NULL);
ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
} }
#else #else
...@@ -1002,3 +1061,8 @@ void ast_sip_initialize_resolver(void) ...@@ -1002,3 +1061,8 @@ void ast_sip_initialize_resolver(void)
} }
#endif #endif
int ast_sip_destroy_resolver(void)
{
ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment