Index: apps/app_rpt.c =================================================================== --- apps/app_rpt.c (revision 83396) +++ apps/app_rpt.c (working copy) @@ -300,7 +300,6 @@ STANDARD_LOCAL_USER; #endif - #define MSWAIT 200 #define HANGTIME 5000 #define TOTIME 180000 @@ -699,60 +698,20 @@ */ /* Debug mode */ -static int rpt_do_debug(int fd, int argc, char *argv[]); -static int rpt_do_dump(int fd, int argc, char *argv[]); -static int rpt_do_stats(int fd, int argc, char *argv[]); -static int rpt_do_lstats(int fd, int argc, char *argv[]); -static int rpt_do_reload(int fd, int argc, char *argv[]); -static int rpt_do_restart(int fd, int argc, char *argv[]); +static char *handle_cli_rpt_debug_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *handle_cli_rpt_dump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *handle_cli_rpt_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *handle_cli_rpt_lstats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *handle_cli_rpt_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *handle_cli_rpt_restart(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); -static char debug_usage[] = -"Usage: rpt debug level {0-7}\n" -" Enables debug messages in app_rpt\n"; - -static char dump_usage[] = -"Usage: rpt dump \n" -" Dumps struct debug info to log\n"; - -static char dump_stats[] = -"Usage: rpt stats \n" -" Dumps node statistics to console\n"; - -static char dump_lstats[] = -"Usage: rpt lstats \n" -" Dumps link statistics to console\n"; - -static char reload_usage[] = -"Usage: rpt reload\n" -" Reloads app_rpt running config parameters\n"; - -static char restart_usage[] = -"Usage: rpt restart\n" -" Restarts app_rpt\n"; - static struct ast_cli_entry cli_rpt[] = { - { { "rpt", "debug", "level" }, - rpt_do_debug, "Enable app_rpt debugging", - debug_usage }, - - { { "rpt", "dump" }, - rpt_do_dump, "Dump app_rpt structs for debugging", - dump_usage }, - - { { "rpt", "stats" }, - rpt_do_stats, "Dump node statistics", - dump_stats }, - { { "rpt", "lstats" }, - rpt_do_lstats, "Dump link statistics", - dump_lstats }, - - { { "rpt", "reload" }, - rpt_do_reload, "Reload app_rpt config", - reload_usage }, - - { { "rpt", "restart" }, - rpt_do_restart, "Restart app_rpt", - restart_usage }, + NEW_CLI(handle_cli_rpt_debug_level, "Enable app_rpt debuggin"), + NEW_CLI(handle_cli_rpt_dump, "Dump app_rpt structs for debugging"), + NEW_CLI(handle_cli_rpt_stats, "Dump node statistics"), + NEW_CLI(handle_cli_rpt_lstats, "Dump link statistics"), + NEW_CLI(handle_cli_rpt_reload, "Reload app_rpt config"), + NEW_CLI(handle_cli_rpt_restart, "Restart app_rpt") }; /* @@ -1130,48 +1089,70 @@ /* * Enable or disable debug output at a given level at the console */ -static int rpt_do_debug(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_debug_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int newlevel; - if (argc != 4) - return RESULT_SHOWUSAGE; - newlevel = myatoi(argv[3]); + switch (cmd) { + case CLI_INIT: + e->command = "rpt debug level"; + e->usage = + "Usage: rpt debug level {0-7}\n" + " Enables debug messages in app_rpt\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 4) + return CLI_SHOWUSAGE; + newlevel = myatoi(a->argv[3]); if ((newlevel < 0) || (newlevel > 7)) - return RESULT_SHOWUSAGE; + return CLI_SHOWUSAGE; if (newlevel) - ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel); + ast_cli(a->fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel); else - ast_cli(fd, "app_rpt Debugging disabled\n"); + ast_cli(a->fd, "app_rpt Debugging disabled\n"); - debug = newlevel; - return RESULT_SUCCESS; + debug = newlevel; + + return CLI_SUCCESS; } /* * Dump rpt struct debugging onto console */ -static int rpt_do_dump(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_dump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i; - if (argc != 3) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "rpt dump"; + e->usage = + "Usage: rpt dump \n" + " Dumps struct debug info to log\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 3) + return CLI_SHOWUSAGE; + for (i = 0; i < nrpts; i++) { - if (!strcmp(argv[2], rpt_vars[i].name)) { + if (!strcmp(a->argv[2], rpt_vars[i].name)) { rpt_vars[i].disgorgetime = time(NULL) + 10; /* Do it 10 seconds later */ - ast_cli(fd, "app_rpt struct dump requested for node %s\n", argv[2]); - return RESULT_SUCCESS; + ast_cli(a->fd, "app_rpt struct dump requested for node %s\n", a->argv[2]); + return CLI_SUCCESS; } } - return RESULT_FAILURE; + return CLI_FAILURE; } /* * Dump statistics onto console */ -static int rpt_do_stats(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i, j; int dailytxtime, dailykerchunks; @@ -1187,9 +1168,20 @@ static char *not_applicable = "N/A"; - if (argc != 3) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "rpt stats"; + e->usage = + "Usage: rpt stats \n" + " Dumps node statistics to console\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 3) + return CLI_SHOWUSAGE; + for (i = 0 ; i <= MAX_STAT_LINKS; i++) listoflinks[i] = NULL; @@ -1199,7 +1191,7 @@ lastdtmfcommand = not_applicable; for (i = 0; i < nrpts; i++) { - if (!strcmp(argv[2], rpt_vars[i].name)) { + if (!strcmp(a->argv[2], rpt_vars[i].name)) { /* Make a copy of all stat variables while locked */ myrpt = &rpt_vars[i]; rpt_mutex_lock(&myrpt->lock); /* LOCK */ @@ -1283,19 +1275,19 @@ rpt_mutex_unlock(&myrpt->lock); /* UNLOCK */ - ast_cli(fd, "************************ NODE %s STATISTICS *************************\n\n", myrpt->name); - ast_cli(fd, "Signal on input..................................: %s\n", input_signal); - ast_cli(fd, "Transmitter enabled..............................: %s\n", enable_state); - ast_cli(fd, "Time out timer state.............................: %s\n", tot_state); - ast_cli(fd, "Time outs since system initialization............: %d\n", timeouts); - ast_cli(fd, "Identifier state.................................: %s\n", ider_state); - ast_cli(fd, "Kerchunks today..................................: %d\n", dailykerchunks); - ast_cli(fd, "Kerchunks since system initialization............: %d\n", totalkerchunks); - ast_cli(fd, "Keyups today.....................................: %d\n", dailykeyups); - ast_cli(fd, "Keyups since system initialization...............: %d\n", totalkeyups); - ast_cli(fd, "DTMF commands today..............................: %d\n", dailyexecdcommands); - ast_cli(fd, "DTMF commands since system initialization........: %d\n", totalexecdcommands); - ast_cli(fd, "Last DTMF command executed.......................: %s\n", lastdtmfcommand); + ast_cli(a->fd, "************************ NODE %s STATISTICS *************************\n\n", myrpt->name); + ast_cli(a->fd, "Signal on input..................................: %s\n", input_signal); + ast_cli(a->fd, "Transmitter enabled..............................: %s\n", enable_state); + ast_cli(a->fd, "Time out timer state.............................: %s\n", tot_state); + ast_cli(a->fd, "Time outs since system initialization............: %d\n", timeouts); + ast_cli(a->fd, "Identifier state.................................: %s\n", ider_state); + ast_cli(a->fd, "Kerchunks today..................................: %d\n", dailykerchunks); + ast_cli(a->fd, "Kerchunks since system initialization............: %d\n", totalkerchunks); + ast_cli(a->fd, "Keyups today.....................................: %d\n", dailykeyups); + ast_cli(a->fd, "Keyups since system initialization...............: %d\n", totalkeyups); + ast_cli(a->fd, "DTMF commands today..............................: %d\n", dailyexecdcommands); + ast_cli(a->fd, "DTMF commands since system initialization........: %d\n", totalexecdcommands); + ast_cli(a->fd, "Last DTMF command executed.......................: %s\n", lastdtmfcommand); hours = dailytxtime / 3600000; dailytxtime %= 3600000; @@ -1304,7 +1296,7 @@ seconds = dailytxtime / 1000; dailytxtime %= 1000; - ast_cli(fd, "TX time today ...................................: %02d:%02d:%02d.%d\n", + ast_cli(a->fd, "TX time today ...................................: %02d:%02d:%02d.%d\n", hours, minutes, seconds, dailytxtime); hours = (int) totaltxtime / 3600000; @@ -1314,57 +1306,69 @@ seconds = (int) totaltxtime / 1000; totaltxtime %= 1000; - ast_cli(fd, "TX time since system initialization..............: %02d:%02d:%02d.%d\n", + ast_cli(a->fd, "TX time since system initialization..............: %02d:%02d:%02d.%d\n", hours, minutes, seconds, (int) totaltxtime); - ast_cli(fd, "Nodes currently connected to us..................: "); + ast_cli(a->fd, "Nodes currently connected to us..................: "); for (j = 0;; j++) { if (!listoflinks[j]) { if (!j) { - ast_cli(fd, ""); + ast_cli(a->fd, ""); } break; } - ast_cli(fd, "%s", listoflinks[j]); + ast_cli(a->fd, "%s", listoflinks[j]); if (j % 4 == 3) { - ast_cli(fd, "\n"); - ast_cli(fd, " : "); + ast_cli(a->fd, "\n"); + ast_cli(a->fd, " : "); } else { if (listoflinks[j + 1]) - ast_cli(fd, ", "); + ast_cli(a->fd, ", "); } } - ast_cli(fd, "\n"); + ast_cli(a->fd, "\n"); - ast_cli(fd, "Last node which transmitted to us................: %s\n", lastnodewhichkeyedusup); - ast_cli(fd, "Autopatch state..................................: %s\n", patch_state); - ast_cli(fd, "Autopatch called number..........................: %s\n", called_number); - ast_cli(fd, "Reverse patch/IAXRPT connected...................: %s\n\n", reverse_patch_state); + ast_cli(a->fd, "Last node which transmitted to us................: %s\n", lastnodewhichkeyedusup); + ast_cli(a->fd, "Autopatch state..................................: %s\n", patch_state); + ast_cli(a->fd, "Autopatch called number..........................: %s\n", called_number); + ast_cli(a->fd, "Reverse patch/IAXRPT connected...................: %s\n\n", reverse_patch_state); - return RESULT_SUCCESS; + return CLI_SUCCESS; } } - return RESULT_FAILURE; + return CLI_FAILURE; } /* * Link stats function */ -static int rpt_do_lstats(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_lstats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i, j; struct rpt *myrpt; struct rpt_link *l; struct rpt_lstat *s, *t; struct rpt_lstat s_head; - if (argc != 3) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "rpt lstats"; + e->usage = + "Usage: rpt lstats \n" + " Dumps link statistics to console\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 3) + return CLI_SHOWUSAGE; + s = NULL; s_head.next = &s_head; s_head.prev = &s_head; for (i = 0; i < nrpts; i++) { - if (!strcmp(argv[2], rpt_vars[i].name)) { + if (!strcmp(a->argv[2], rpt_vars[i].name)) { /* Make a copy of all stat variables while locked */ myrpt = &rpt_vars[i]; rpt_mutex_lock(&myrpt->lock); /* LOCK */ @@ -1379,7 +1383,7 @@ if ((s = ast_calloc(1, sizeof(*s))) == NULL) { ast_log(LOG_ERROR, "Malloc failed in rpt_do_lstats\n"); rpt_mutex_unlock(&myrpt->lock); /* UNLOCK */ - return RESULT_FAILURE; + return CLI_FAILURE; } ast_copy_string(s->name, l->name, MAXREMSTR); pbx_substitute_variables_helper(l->chan, "${IAXPEER(CURRENTCHANNEL)}", s->peer, MAXPEERSTR - 1); @@ -1391,8 +1395,8 @@ l = l->next; } rpt_mutex_unlock(&myrpt->lock); /* UNLOCK */ - ast_cli(fd, "NODE PEER RECONNECTS DIRECTION CONNECT TIME\n"); - ast_cli(fd, "---- ---- ---------- --------- ------------\n"); + ast_cli(a->fd, "NODE PEER RECONNECTS DIRECTION CONNECT TIME\n"); + ast_cli(a->fd, "---- ---- ---------- --------- ------------\n"); for (s = s_head.next; s != &s_head; s = s->next) { int hours, minutes, seconds; @@ -1406,7 +1410,7 @@ connecttime %= 1000; snprintf(conntime, sizeof(conntime), "%02d:%02d:%02d.%d", hours, minutes, seconds, (int) connecttime); - ast_cli(fd, "%-10s%-20s%-12d%-11s%-30s\n", + ast_cli(a->fd, "%-10s%-20s%-12d%-11s%-30s\n", s->name, s->peer, s->reconnects, (s->outbound)? "OUT":"IN", conntime); } /* destroy our local link queue */ @@ -1417,42 +1421,65 @@ remque((struct qelem *)t); ast_free(t); } - return RESULT_SUCCESS; + return CLI_SUCCESS; } } - return RESULT_FAILURE; + + return CLI_FAILURE; } /* * reload vars */ -static int rpt_do_reload(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int n; - if (argc > 2) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "rpt reload"; + e->usage = + "Usage: rpt reload\n" + " Reloads app_rpt running config parameters\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc > 2) + return CLI_SHOWUSAGE; + for (n = 0; n < nrpts; n++) rpt_vars[n].reload = 1; - return RESULT_FAILURE; + return CLI_SUCCESS; } /* * restart app_rpt */ -static int rpt_do_restart(int fd, int argc, char *argv[]) +static char *handle_cli_rpt_restart(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i; - if (argc > 2) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "rpt restart"; + e->usage = + "Usage: rpt restart\n" + " Restarts app_rpt\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc > 2) + return CLI_SHOWUSAGE; for (i = 0; i < nrpts; i++) { if (rpt_vars[i].rxchannel) ast_softhangup(rpt_vars[i].rxchannel, AST_SOFTHANGUP_DEV); } - return RESULT_FAILURE; + return CLI_SUCCESS; } static int play_tone_pair(struct ast_channel *chan, int f1, int f2, int duration, int amplitude) @@ -4627,7 +4654,7 @@ char multimode = 0; char oc; char tmp[20], freq[20] = "", savestr[20] = ""; - int mhz, decimals; + int mhz = 0, decimals = 0; struct ast_channel *mychannel; AST_DECLARE_APP_ARGS(args1, AST_APP_ARG(freq); @@ -6800,7 +6827,7 @@ { int res = -1, i, rem_totx, n, phone_mode = 0; char *tmp, keyed = 0; - char *options, *tele, c; + char *options = NULL, *tele, c; struct rpt *myrpt; struct ast_frame *f; struct ast_channel *who;