Index: cli.c =================================================================== RCS file: /usr/cvsroot/asterisk/cli.c,v retrieving revision 1.79 diff -u -r1.79 cli.c --- cli.c 29 Apr 2005 17:00:33 -0000 1.79 +++ cli.c 13 May 2005 07:04:51 -0000 @@ -992,6 +992,25 @@ return 0; } +/* + * register/unregister an array of entries. + */ +void ast_cli_register_n(struct ast_cli_entry *e, int len) +{ + int i; + + for (i=0; i < len; i++) + ast_cli_register(e + i); +} + +void ast_cli_unregister_n(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] = ""; Index: frame.c =================================================================== RCS file: /usr/cvsroot/asterisk/frame.c,v retrieving revision 1.52 diff -u -r1.52 frame.c --- frame.c 22 Apr 2005 13:11:34 -0000 1.52 +++ frame.c 13 May 2005 07:04:52 -0000 @@ -590,15 +612,6 @@ "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; @@ -625,9 +638,6 @@ "Usage: show codec \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"; @@ -809,21 +819,23 @@ 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_n(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) ); return 0; } Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.728 diff -u -r1.728 chan_sip.c --- channels/chan_sip.c 8 May 2005 16:49:28 -0000 1.728 +++ channels/chan_sip.c 13 May 2005 07:05:17 -0000 @@ -7830,51 +7830,6 @@ 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", @@ -11035,8 +10990,34 @@ 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() @@ -11061,28 +11042,7 @@ 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_n(my_clis, sizeof(my_clis)/ sizeof(my_clis[0])); ast_rtp_proto_register(&sip_rtp); @@ -11119,28 +11079,7 @@ 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_n(my_clis, sizeof(my_clis)/ sizeof(my_clis[0])); ast_rtp_proto_unregister(&sip_rtp); Index: include/asterisk/cli.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/cli.h,v retrieving revision 1.7 diff -u -r1.7 cli.h --- include/asterisk/cli.h 15 Jan 2005 23:48:12 -0000 1.7 +++ include/asterisk/cli.h 13 May 2005 07:05:22 -0000 @@ -57,22 +57,35 @@ */ 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_n(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_n(struct ast_cli_entry *e, int len); /*! Readline madness */ /* Useful for readline, that's about it