diff options
Diffstat (limited to 'main/udptl.c')
-rw-r--r-- | main/udptl.c | 147 |
1 files changed, 90 insertions, 57 deletions
diff --git a/main/udptl.c b/main/udptl.c index 12de3fd53..6ce344328 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1087,7 +1087,7 @@ int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, return -1; } -static char *handle_cli_udptl_debug_ip(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +static char *handle_cli_udptl_debug_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct hostent *hp; struct ast_hostent ahp; @@ -1097,89 +1097,122 @@ static char *handle_cli_udptl_debug_ip(struct ast_cli_entry *e, int cmd, struct switch (cmd) { case CLI_INIT: - e->command = "udptl debug ip"; - e->usage = - "Usage: udptl debug [ip host[:port]]\n" - " Enable dumping of all UDPTL packets to and from host.\n"; + e->command = "udptl debug [off|ip]"; + e->usage = + "Usage: udptl debug [off]|[ip host[:port]]\n" + " Enable or disable dumping of UDPTL packets.\n" + " If ip is specified, limit the dumped packets to those to and from\n" + " the specified 'host' with optional port.\n"; return NULL; case CLI_GENERATE: return NULL; } - port = 0; - - if (a->argc != 4) - return CLI_SHOWUSAGE; - arg = a->argv[3]; - p = strstr(arg, ":"); - if (p) { - *p = '\0'; - p++; - port = atoi(p); - } - hp = ast_gethostbyname(arg, &ahp); - if (hp == NULL) + if (a->argc < 2 || a->argc > 4) return CLI_SHOWUSAGE; - udptldebugaddr.sin_family = AF_INET; - memcpy(&udptldebugaddr.sin_addr, hp->h_addr, sizeof(udptldebugaddr.sin_addr)); - udptldebugaddr.sin_port = htons(port); - if (port == 0) - ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_inet_ntoa(udptldebugaddr.sin_addr)); - else - ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(udptldebugaddr.sin_addr), port); - udptldebug = 1; - return CLI_SUCCESS; -} -static char *handle_cli_udptl_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) -{ - switch (cmd) { - case CLI_INIT: - e->command = "udptl debug"; - e->usage = - "Usage: udptl debug\n" - " Enable dumping of all UDPTL packets.\n"; - return NULL; - case CLI_GENERATE: - return NULL; + if (a->argc == 2) { + udptldebug = 1; + memset(&udptldebugaddr, 0, sizeof(udptldebugaddr)); + ast_cli(a->fd, "UDPTL Debugging Enabled\n"); + } else if (a->argc == 3) { + if (strncasecmp(a->argv[2], "off", 3)) + return CLI_SHOWUSAGE; + udptldebug = 0; + ast_cli(a->fd, "UDPTL Debugging Disabled\n"); + } else { + if (strncasecmp(a->argv[2], "ip", 2)) + return CLI_SHOWUSAGE; + port = 0; + arg = a->argv[3]; + p = strstr(arg, ":"); + if (p) { + *p = '\0'; + p++; + port = atoi(p); + } + hp = ast_gethostbyname(arg, &ahp); + if (hp == NULL) + return CLI_SHOWUSAGE; + udptldebugaddr.sin_family = AF_INET; + memcpy(&udptldebugaddr.sin_addr, hp->h_addr, sizeof(udptldebugaddr.sin_addr)); + udptldebugaddr.sin_port = htons(port); + if (port == 0) + ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_inet_ntoa(udptldebugaddr.sin_addr)); + else + ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(udptldebugaddr.sin_addr), port); + udptldebug = 1; } - if (a->argc != 2) - return CLI_SHOWUSAGE; - - udptldebug = 1; - memset(&udptldebugaddr, 0, sizeof(udptldebugaddr)); - - ast_cli(a->fd, "UDPTL Debugging Enabled\n"); return CLI_SUCCESS; } -static char *handle_cli_udptl_debug_off(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +static char *handle_cli_udptl_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { + struct hostent *hp; + struct ast_hostent ahp; + int port; + char *p; + char *arg; + switch (cmd) { case CLI_INIT: - e->command = "udptl debug off"; - e->usage = - "Usage: udptl debug off\n" - " Disable dumping of all UDPTL packets.\n"; + e->command = "udptl set debug {on|off|ip}"; + e->usage = + "Usage: udptl set debug {on|off|ip host[:port]}\n" + " Enable or disable dumping of UDPTL packets.\n" + " If ip is specified, limit the dumped packets to those to and from\n" + " the specified 'host' with optional port.\n"; return NULL; case CLI_GENERATE: return NULL; } - if (a->argc != 3) + if (a->argc < 4 || a->argc > 5) return CLI_SHOWUSAGE; - udptldebug = 0; + if (a->argc == 4) { + if (!strncasecmp(a->argv[3], "on", 2)) { + udptldebug = 1; + memset(&udptldebugaddr, 0, sizeof(udptldebugaddr)); + ast_cli(a->fd, "UDPTL Debugging Enabled\n"); + } else if (!strncasecmp(a->argv[3], "off", 3)) { + udptldebug = 0; + ast_cli(a->fd, "UDPTL Debugging Disabled\n"); + } else { + return CLI_SHOWUSAGE; + } + } else { + if (strncasecmp(a->argv[3], "ip", 2)) + return CLI_SHOWUSAGE; + port = 0; + arg = a->argv[4]; + p = strstr(arg, ":"); + if (p) { + *p = '\0'; + p++; + port = atoi(p); + } + hp = ast_gethostbyname(arg, &ahp); + if (hp == NULL) + return CLI_SHOWUSAGE; + udptldebugaddr.sin_family = AF_INET; + memcpy(&udptldebugaddr.sin_addr, hp->h_addr, sizeof(udptldebugaddr.sin_addr)); + udptldebugaddr.sin_port = htons(port); + if (port == 0) + ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_inet_ntoa(udptldebugaddr.sin_addr)); + else + ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(udptldebugaddr.sin_addr), port); + udptldebug = 1; + } - ast_cli(a->fd, "UDPTL Debugging Disabled\n"); return CLI_SUCCESS; } +static struct ast_cli_entry cli_handle_udptl_debug_deprecated = AST_CLI_DEFINE(handle_cli_udptl_debug_deprecated, "Enable/Disable UDPTL debugging"); + static struct ast_cli_entry cli_udptl[] = { - AST_CLI_DEFINE(handle_cli_udptl_debug, "Enable UDPTL debugging"), - AST_CLI_DEFINE(handle_cli_udptl_debug_ip, "Enable UDPTL debugging on IP"), - AST_CLI_DEFINE(handle_cli_udptl_debug_off, "Disable UDPTL debugging") + AST_CLI_DEFINE(handle_cli_udptl_set_debug, "Enable/Disable UDPTL debugging", .deprecate_cmd = &cli_handle_udptl_debug_deprecated) }; static void __ast_udptl_reload(int reload) |