aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 03:03:48 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 03:03:48 +0000
commitf5c1139da439fb8cb79ed06fd958658cef50ef89 (patch)
tree8b39f6d3ade5b8cc43941163e2fb95ddfb83cbf9
parentc3b40fbb666414f4d5e5a1ae63272a79d438af88 (diff)
add functions to register/unregister multiple CLI commands in a single operation (bug #4255, with minor mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5662 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xchannels/chan_sip.c121
-rwxr-xr-xcli.c19
-rwxr-xr-xframe.c34
-rwxr-xr-xinclude/asterisk/cli.h25
4 files changed, 80 insertions, 119 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 8ddd1ef1d..23376bab3 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -7856,51 +7856,6 @@ static char *func_header_read(struct ast_channel *chan, char *cmd, char *data, c
return buf;
}
-static struct ast_cli_entry cli_notify =
- { { "sip", "notify", NULL }, sip_notify, "Send a notify packet to a SIP peer", notify_usage, complete_sipnotify };
-static struct ast_cli_entry cli_show_objects =
- { { "sip", "show", "objects", NULL }, sip_show_objects, "Show all SIP object allocations", show_objects_usage };
-static struct ast_cli_entry cli_show_users =
- { { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage };
-static struct ast_cli_entry cli_show_user =
- { { "sip", "show", "user", NULL }, sip_show_user, "Show details on specific SIP user", show_user_usage, complete_sip_show_user };
-static struct ast_cli_entry cli_show_subscriptions =
- { { "sip", "show", "subscriptions", NULL }, sip_show_subscriptions, "Show active SIP subscriptions", show_subscriptions_usage};
-static struct ast_cli_entry cli_show_channels =
- { { "sip", "show", "channels", NULL }, sip_show_channels, "Show active SIP channels", show_channels_usage};
-static struct ast_cli_entry cli_show_channel =
- { { "sip", "show", "channel", NULL }, sip_show_channel, "Show detailed SIP channel info", show_channel_usage, complete_sipch };
-static struct ast_cli_entry cli_show_history =
- { { "sip", "show", "history", NULL }, sip_show_history, "Show SIP dialog history", show_history_usage, complete_sipch };
-static struct ast_cli_entry cli_debug_ip =
- { { "sip", "debug", "ip", NULL }, sip_do_debug, "Enable SIP debugging on IP", debug_usage };
-static struct ast_cli_entry cli_debug_peer =
- { { "sip", "debug", "peer", NULL }, sip_do_debug, "Enable SIP debugging on Peername", debug_usage, complete_sip_debug_peer };
-static struct ast_cli_entry cli_show_peer =
- { { "sip", "show", "peer", NULL }, sip_show_peer, "Show details on specific SIP peer", show_peer_usage, complete_sip_show_peer };
-static struct ast_cli_entry cli_show_peers =
- { { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
-static struct ast_cli_entry cli_prune_realtime =
- { { "sip", "prune", "realtime", NULL }, sip_prune_realtime,
- "Prune cached Realtime object(s)", prune_realtime_usage };
-static struct ast_cli_entry cli_prune_realtime_peer =
- { { "sip", "prune", "realtime", "peer", NULL }, sip_prune_realtime,
- "Prune cached Realtime peer(s)", prune_realtime_usage, complete_sip_prune_realtime_peer };
-static struct ast_cli_entry cli_prune_realtime_user =
- { { "sip", "prune", "realtime", "user", NULL }, sip_prune_realtime,
- "Prune cached Realtime user(s)", prune_realtime_usage, complete_sip_prune_realtime_user };
-static struct ast_cli_entry cli_inuse_show =
- { { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limits", show_inuse_usage };
-static struct ast_cli_entry cli_show_registry =
- { { "sip", "show", "registry", NULL }, sip_show_registry, "Show SIP registration status", show_reg_usage };
-static struct ast_cli_entry cli_debug =
- { { "sip", "debug", NULL }, sip_do_debug, "Enable SIP debugging", debug_usage };
-static struct ast_cli_entry cli_history =
- { { "sip", "history", NULL }, sip_do_history, "Enable SIP history", history_usage };
-static struct ast_cli_entry cli_no_history =
- { { "sip", "no", "history", NULL }, sip_no_history, "Disable SIP history", no_history_usage };
-static struct ast_cli_entry cli_no_debug =
- { { "sip", "no", "debug", NULL }, sip_no_debug, "Disable SIP debugging", no_debug_usage };
static struct ast_custom_function sip_header_function = {
.name = "SIP_HEADER",
@@ -11067,8 +11022,34 @@ int reload(void)
return sip_reload(0, 0, NULL);
}
-static struct ast_cli_entry cli_sip_reload =
- { { "sip", "reload", NULL }, sip_reload, "Reload SIP configuration", sip_reload_usage };
+// static struct ast_cli_entry cli_sip_reload =
+static struct ast_cli_entry my_clis[] = {
+ { { "sip", "notify", NULL }, sip_notify, "Send a notify packet to a SIP peer", notify_usage, complete_sipnotify },
+ { { "sip", "show", "objects", NULL }, sip_show_objects, "Show all SIP object allocations", show_objects_usage },
+ { { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage },
+ { { "sip", "show", "user", NULL }, sip_show_user, "Show details on specific SIP user", show_user_usage, complete_sip_show_user },
+ { { "sip", "show", "subscriptions", NULL }, sip_show_subscriptions, "Show active SIP subscriptions", show_subscriptions_usage},
+ { { "sip", "show", "channels", NULL }, sip_show_channels, "Show active SIP channels", show_channels_usage},
+ { { "sip", "show", "channel", NULL }, sip_show_channel, "Show detailed SIP channel info", show_channel_usage, complete_sipch },
+ { { "sip", "show", "history", NULL }, sip_show_history, "Show SIP dialog history", show_history_usage, complete_sipch },
+ { { "sip", "debug", "ip", NULL }, sip_do_debug, "Enable SIP debugging on IP", debug_usage },
+ { { "sip", "debug", "peer", NULL }, sip_do_debug, "Enable SIP debugging on Peername", debug_usage, complete_sip_debug_peer },
+ { { "sip", "show", "peer", NULL }, sip_show_peer, "Show details on specific SIP peer", show_peer_usage, complete_sip_show_peer },
+ { { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage },
+ { { "sip", "prune", "realtime", NULL }, sip_prune_realtime,
+ "Prune cached Realtime object(s)", prune_realtime_usage },
+ { { "sip", "prune", "realtime", "peer", NULL }, sip_prune_realtime,
+ "Prune cached Realtime peer(s)", prune_realtime_usage, complete_sip_prune_realtime_peer },
+ { { "sip", "prune", "realtime", "user", NULL }, sip_prune_realtime,
+ "Prune cached Realtime user(s)", prune_realtime_usage, complete_sip_prune_realtime_user },
+ { { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limits", show_inuse_usage },
+ { { "sip", "show", "registry", NULL }, sip_show_registry, "Show SIP registration status", show_reg_usage },
+ { { "sip", "debug", NULL }, sip_do_debug, "Enable SIP debugging", debug_usage },
+ { { "sip", "history", NULL }, sip_do_history, "Enable SIP history", history_usage },
+ { { "sip", "no", "history", NULL }, sip_no_history, "Disable SIP history", no_history_usage },
+ { { "sip", "no", "debug", NULL }, sip_no_debug, "Disable SIP debugging", no_debug_usage },
+ { { "sip", "reload", NULL }, sip_reload, "Reload SIP configuration", sip_reload_usage },
+};
/*--- load_module: PBX load module - initialization ---*/
int load_module()
@@ -11093,28 +11074,7 @@ int load_module()
if (reload_config())
return -1;
- ast_cli_register(&cli_notify);
- ast_cli_register(&cli_show_users);
- ast_cli_register(&cli_show_user);
- ast_cli_register(&cli_show_objects);
- ast_cli_register(&cli_show_subscriptions);
- ast_cli_register(&cli_show_channels);
- ast_cli_register(&cli_show_channel);
- ast_cli_register(&cli_show_history);
- ast_cli_register(&cli_prune_realtime);
- ast_cli_register(&cli_prune_realtime_peer);
- ast_cli_register(&cli_prune_realtime_user);
- ast_cli_register(&cli_show_peer);
- ast_cli_register(&cli_show_peers);
- ast_cli_register(&cli_show_registry);
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_debug_ip);
- ast_cli_register(&cli_debug_peer);
- ast_cli_register(&cli_no_debug);
- ast_cli_register(&cli_history);
- ast_cli_register(&cli_no_history);
- ast_cli_register(&cli_sip_reload);
- ast_cli_register(&cli_inuse_show);
+ ast_cli_register_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
ast_rtp_proto_register(&sip_rtp);
@@ -11151,28 +11111,7 @@ int unload_module()
ast_unregister_application(app_sipaddheader);
ast_unregister_application(app_sipgetheader);
- ast_cli_unregister(&cli_notify);
- ast_cli_unregister(&cli_show_users);
- ast_cli_unregister(&cli_show_user);
- ast_cli_unregister(&cli_show_objects);
- ast_cli_unregister(&cli_show_channels);
- ast_cli_unregister(&cli_show_channel);
- ast_cli_unregister(&cli_show_history);
- ast_cli_unregister(&cli_prune_realtime_user);
- ast_cli_unregister(&cli_prune_realtime_peer);
- ast_cli_unregister(&cli_prune_realtime);
- ast_cli_unregister(&cli_show_peer);
- ast_cli_unregister(&cli_show_peers);
- ast_cli_unregister(&cli_show_registry);
- ast_cli_unregister(&cli_show_subscriptions);
- ast_cli_unregister(&cli_debug);
- ast_cli_unregister(&cli_debug_ip);
- ast_cli_unregister(&cli_debug_peer);
- ast_cli_unregister(&cli_no_debug);
- ast_cli_unregister(&cli_history);
- ast_cli_unregister(&cli_no_history);
- ast_cli_unregister(&cli_sip_reload);
- ast_cli_unregister(&cli_inuse_show);
+ ast_cli_unregister_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
ast_rtp_proto_unregister(&sip_rtp);
diff --git a/cli.c b/cli.c
index f5865cc1e..141ac09ae 100755
--- a/cli.c
+++ b/cli.c
@@ -992,6 +992,25 @@ int ast_cli_register(struct ast_cli_entry *e)
return 0;
}
+/*
+ * register/unregister an array of entries.
+ */
+void ast_cli_register_multiple(struct ast_cli_entry *e, int len)
+{
+ int i;
+
+ for (i=0; i < len; i++)
+ ast_cli_register(e + i);
+}
+
+void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
+{
+ int i;
+
+ for (i=0; i < len; i++)
+ ast_cli_unregister(e + i);
+}
+
static int help_workhorse(int fd, char *match[])
{
char fullcmd1[80] = "";
diff --git a/frame.c b/frame.c
index 2e68ec4ff..b75c38932 100755
--- a/frame.c
+++ b/frame.c
@@ -596,15 +596,6 @@ static char frame_show_codecs_usage[] =
"Usage: show [audio|video|image] codecs\n"
" Displays codec mapping\n";
-struct ast_cli_entry cli_show_codecs =
-{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage };
-struct ast_cli_entry cli_show_codecs_audio =
-{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage };
-struct ast_cli_entry cli_show_codecs_video =
-{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage };
-struct ast_cli_entry cli_show_codecs_image =
-{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage };
-
static int show_codec_n(int fd, int argc, char *argv[])
{
int codec, i, found=0;
@@ -631,9 +622,6 @@ static char frame_show_codec_n_usage[] =
"Usage: show codec <number>\n"
" Displays codec mapping\n";
-struct ast_cli_entry cli_show_codec_n =
-{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage };
-
void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
{
char *n = "unknown";
@@ -815,21 +803,23 @@ static int show_frame_stats(int fd, int argc, char *argv[])
static char frame_stats_usage[] =
"Usage: show frame stats\n"
" Displays debugging statistics from framer\n";
+#endif
-struct ast_cli_entry cli_frame_stats =
-{ { "show", "frame", "stats", NULL }, show_frame_stats, "Shows frame statistics", frame_stats_usage };
+/* XXX no unregister function here ??? */
+static struct ast_cli_entry my_clis[] = {
+{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage },
+{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage },
+{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage },
+{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage },
+{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage },
+#ifdef TRACE_FRAMES
+{ { "show", "frame", "stats", NULL }, show_frame_stats, "Shows frame statistics", frame_stats_usage },
#endif
+};
int init_framer(void)
{
-#ifdef TRACE_FRAMES
- ast_cli_register(&cli_frame_stats);
-#endif
- ast_cli_register(&cli_show_codecs);
- ast_cli_register(&cli_show_codecs_audio);
- ast_cli_register(&cli_show_codecs_video);
- ast_cli_register(&cli_show_codecs_image);
- ast_cli_register(&cli_show_codec_n);
+ ast_cli_register_multiple(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) );
return 0;
}
diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h
index bc280220c..993b61687 100755
--- a/include/asterisk/cli.h
+++ b/include/asterisk/cli.h
@@ -57,23 +57,36 @@ struct ast_cli_entry {
*/
extern int ast_cli_command(int fd, char *s);
-/*! Registers a command */
+/*! Registers a command or an array of commands */
/*!
- * \param fd File descriptor that I/O is done to
- * \param s string given at prompt
+ * \param e which cli entry to register
* Register your own command
* Returns 0 on success, -1 on failure
*/
extern int ast_cli_register(struct ast_cli_entry *e);
-/*! Unregisters a command */
+/*!
+ * \param e pointer to first cli entry to register
+ * \param len number of entries to register
+ * Register multiple commands
+ */
+extern void ast_cli_register_multiple(struct ast_cli_entry *e, int len);
+
+/*! Unregisters a command or an array of commands */
/*!
* \param e which cli entry to unregister
- * Unregister your own command. You must pass a completed ast_cli_entry structur
- * Returns 0 on success, -1 on failure
+ * Unregister your own command. You must pass a completed ast_cli_entry structure
+ * Returns 0.
*/
extern int ast_cli_unregister(struct ast_cli_entry *e);
+/*!
+ * \param e pointer to first cli entry to unregister
+ * \param len number of entries to unregister
+ * Unregister multiple commands
+ */
+extern void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
+
/*! Readline madness */
/* Useful for readline, that's about it
* Returns 0 on success, -1 on failure