Wed Jan 8 2020 09:50:10

Asterisk developer's documentation


cli.h File Reference

Standard Command Line Interface. More...

Go to the source code of this file.

Data Structures

struct  ast_cli_args
 
struct  ast_cli_entry
 descriptor for a cli entry. More...
 

Macros

#define ast_cli_command(fd, s)   ast_cli_command_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, s)
 
#define ast_cli_command_multiple(fd, size, s)   ast_cli_command_multiple_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, size, s)
 
#define AST_CLI_COMPLETE_EOF   "_EOF_"
 
#define AST_CLI_DEFINE(fn, txt,...)   { .handler = fn, .summary = txt, ## __VA_ARGS__ }
 
#define AST_CLI_ONOFF(x)   (x) ? "On" : "Off"
 return On or Off depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point). More...
 
#define AST_CLI_YESNO(x)   (x) ? "Yes" : "No"
 return Yes or No depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point). More...
 
#define AST_MAX_ARGS   64
 
#define AST_MAX_CMD_LEN   16
 
#define CLI_FAILURE   (char *)RESULT_FAILURE
 
#define CLI_NO_PERMS   -1
 
#define CLI_SHOWUSAGE   (char *)RESULT_SHOWUSAGE
 
#define CLI_SUCCESS   (char *)RESULT_SUCCESS
 
#define ESS(x)   ((x) == 1 ? "" : "s")
 
#define RESULT_FAILURE   2
 
#define RESULT_SHOWUSAGE   1
 
#define RESULT_SUCCESS   0
 

Enumerations

enum  ast_cli_command { CLI_INIT = -2, CLI_GENERATE = -3, CLI_HANDLER = -4 }
 calling arguments for new-style handlers. More...
 

Functions

void ast_cli (int fd, const char *fmt,...)
 
int ast_cli_command_full (int uid, int gid, int fd, const char *s)
 Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions. More...
 
int ast_cli_command_multiple_full (int uid, int gid, int fd, size_t size, const char *s)
 Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions. More...
 
char * ast_cli_complete (const char *word, const char *const choices[], int pos)
 
char ** ast_cli_completion_matches (const char *, const char *)
 Generates a NULL-terminated array of strings that 1) begin with the string in the second parameter, and 2) are valid in a command after the string in the first parameter. More...
 
char * ast_cli_generator (const char *, const char *, int)
 Readline madness Useful for readline, that's about it. More...
 
int ast_cli_generatornummatches (const char *, const char *)
 Return the number of unique matches for the generator. More...
 
int ast_cli_register (struct ast_cli_entry *e)
 Registers a command or an array of commands. More...
 
int ast_cli_register_multiple (struct ast_cli_entry *e, int len)
 Register multiple commands. More...
 
int ast_cli_unregister (struct ast_cli_entry *e)
 Unregisters a command or an array of commands. More...
 
int ast_cli_unregister_multiple (struct ast_cli_entry *e, int len)
 Unregister multiple commands. More...
 
char * ast_complete_channels (const char *line, const char *word, int pos, int state, int rpos)
 Command completion for the list of active channels. More...
 

Detailed Description

Standard Command Line Interface.

Definition in file cli.h.

Macro Definition Documentation

#define ast_cli_command (   fd,
 
)    ast_cli_command_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, s)

Definition at line 226 of file cli.h.

#define ast_cli_command_multiple (   fd,
  size,
 
)    ast_cli_command_multiple_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, size, s)

Definition at line 242 of file cli.h.

#define AST_CLI_COMPLETE_EOF   "_EOF_"

Definition at line 51 of file cli.h.

Referenced by ast_el_strtoarr(), cli_complete(), and handle_commandmatchesarray().

#define AST_CLI_DEFINE (   fn,
  txt,
  ... 
)    { .handler = fn, .summary = txt, ## __VA_ARGS__ }

Definition at line 191 of file cli.h.

#define AST_CLI_ONOFF (   x)    (x) ? "On" : "Off"

return On or Off depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point).

Definition at line 72 of file cli.h.

Referenced by sip_show_settings().

#define AST_CLI_YESNO (   x)    (x) ? "Yes" : "No"

return Yes or No depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point).

Definition at line 65 of file cli.h.

Referenced by _sip_show_peer(), action_coresettings(), display_nat_warning(), handle_feature_show(), handle_manager_show_settings(), handle_skinny_show_settings(), show_channels_cb(), sip_show_channel(), sip_show_mwi(), sip_show_settings(), sip_show_user(), and sip_show_users().

#define AST_MAX_ARGS   64

Definition at line 49 of file cli.h.

Referenced by __ast_cli_generator(), ast_cli_command_full(), and handle_cli_check_permissions().

#define AST_MAX_CMD_LEN   16

Definition at line 47 of file cli.h.

Referenced by __ast_cli_register(), and find_best().

#define CLI_FAILURE   (char *)RESULT_FAILURE

Definition at line 45 of file cli.h.

Referenced by _sip_show_peers(), ais_clm_show_members(), aji_cli_create_collection(), aji_cli_create_leafnode(), aji_cli_delete_pubsub_node(), aji_cli_list_pubsub_nodes(), aji_cli_purge_pubsub_nodes(), ast_cli_command_full(), cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), cli_console_sendtext(), cli_fax_show_sessions(), cli_odbc_read(), cli_odbc_write(), cli_realtime_destroy(), cli_realtime_store(), cli_realtime_update(), cli_realtime_update2(), cli_tps_ping(), console_answer(), console_autoanswer(), console_cmd(), console_dial(), console_do_answer(), console_flash(), console_hangup(), console_sendtext(), console_transfer(), dahdi_destroy_channel(), dahdi_restart_cmd(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_status(), handle_cc_status(), handle_chanlist(), handle_cli_ael_reload(), handle_cli_agi_add_cmd(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_cli_core_show_channeltype(), handle_cli_core_show_translation(), handle_cli_data_get(), handle_cli_devstate_change(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_ignorepat(), handle_cli_dialplan_add_include(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_remove_ignorepat(), handle_cli_dialplan_remove_include(), handle_cli_dialplan_save(), handle_cli_file_convert(), handle_cli_iax2_set_debug(), handle_cli_iax2_show_peers(), handle_cli_indication_add(), handle_cli_indication_remove(), handle_cli_realtime_pgsql_status(), handle_cli_status(), handle_cli_ulimit(), handle_commandmatchesarray(), handle_debug_dialplan(), handle_load(), handle_logger_reload(), handle_logger_rotate(), handle_mfcr2_set_debug(), handle_mfcr2_show_variants(), handle_minivm_list_templates(), handle_minivm_show_users(), handle_minivm_show_zones(), handle_pri_service_generic(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_remove_member(), handle_queue_set_member_penalty(), handle_redirect(), handle_set_chanvar(), handle_show_application(), handle_show_chanvar(), handle_show_dialplan(), handle_show_function(), handle_showchan(), handle_softhangup(), handle_unload(), handle_verbose(), handle_voicemail_show_users(), handle_voicemail_show_zones(), meetme_cmd_helper(), meetme_show_cmd(), realtime_ldap_status(), rtcp_do_debug_ip(), rtp_do_debug_ip(), show_users_realtime(), sip_cli_notify(), and timing_test().

#define CLI_NO_PERMS   -1

Definition at line 37 of file cli.h.

Referenced by cli_has_permissions().

#define CLI_SHOWUSAGE   (char *)RESULT_SHOWUSAGE

Definition at line 44 of file cli.h.

Referenced by __queues_show(), __say_cli_init(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), agent_logoff_cmd(), agents_show(), agents_show_online(), ais_clm_show_members(), ais_evt_show_event_channels(), aji_cli_create_collection(), aji_cli_create_leafnode(), aji_cli_delete_pubsub_node(), aji_cli_list_pubsub_nodes(), aji_cli_purge_pubsub_nodes(), aji_do_set_debug(), aoc_cli_debug_enable(), ast_cli_command_full(), cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), cli_console_sendtext(), cli_fax_set_debug(), cli_fax_show_session(), cli_fax_show_version(), cli_list_available(), cli_list_devices(), cli_odbc_read(), cli_odbc_write(), cli_realtime_destroy(), cli_realtime_load(), cli_realtime_store(), cli_realtime_update(), cli_realtime_update2(), cli_tps_ping(), cli_tps_report(), console_active(), console_answer(), console_autoanswer(), console_cmd(), console_dial(), console_flash(), console_hangup(), console_mute(), console_sendtext(), console_transfer(), dahdi_destroy_channel(), dahdi_restart_cmd(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_flush(), dundi_set_debug(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peer(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), dundi_store_history(), event_dump_cache(), group_show_channels(), gtalk_show_channels(), handle_abort_shutdown(), handle_cc_kill(), handle_cc_status(), handle_chanlist(), handle_cli_ael_reload(), handle_cli_ael_set_debug(), handle_cli_agi_add_cmd(), handle_cli_agi_debug(), handle_cli_agi_dump_html(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_cli_config_reload(), handle_cli_core_show_channeltype(), handle_cli_core_show_channeltypes(), handle_cli_core_show_file_formats(), handle_cli_core_show_translation(), handle_cli_data_get(), handle_cli_database_del(), handle_cli_database_deltree(), handle_cli_database_get(), handle_cli_database_put(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_devstate_change(), handle_cli_devstate_list(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_ignorepat(), handle_cli_dialplan_add_include(), handle_cli_dialplan_reload(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_remove_ignorepat(), handle_cli_dialplan_remove_include(), handle_cli_dialplan_save(), handle_cli_file_convert(), handle_cli_h323_cycle_gk(), handle_cli_h323_hangup(), handle_cli_h323_reload(), handle_cli_h323_set_debug(), handle_cli_h323_set_trace(), handle_cli_h323_show_tokens(), handle_cli_h323_show_version(), handle_cli_iax2_provision(), handle_cli_iax2_prune_realtime(), handle_cli_iax2_set_debug(), handle_cli_iax2_set_debug_jb(), handle_cli_iax2_set_debug_trunk(), handle_cli_iax2_set_mtu(), handle_cli_iax2_show_callno_limits(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_firmware(), handle_cli_iax2_show_netstats(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_peers(), handle_cli_iax2_show_registry(), handle_cli_iax2_show_stats(), handle_cli_iax2_show_threads(), handle_cli_iax2_show_users(), handle_cli_iax2_test_losspct(), handle_cli_iax2_unregister(), handle_cli_indication_add(), handle_cli_indication_remove(), handle_cli_keys_init(), handle_cli_misdn_port_block(), handle_cli_misdn_port_down(), handle_cli_misdn_port_unblock(), handle_cli_misdn_port_up(), handle_cli_misdn_reload(), handle_cli_misdn_restart_pid(), handle_cli_misdn_restart_port(), handle_cli_misdn_send_digit(), handle_cli_misdn_send_display(), handle_cli_misdn_send_facility(), handle_cli_misdn_send_restart(), handle_cli_misdn_set_crypt_debug(), handle_cli_misdn_set_debug(), handle_cli_misdn_set_tics(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_config(), handle_cli_misdn_show_port(), handle_cli_misdn_show_ports_stats(), handle_cli_misdn_show_stacks(), handle_cli_misdn_toggle_echocancel(), handle_cli_mixmonitor(), handle_cli_moh_reload(), handle_cli_moh_show_classes(), handle_cli_moh_show_files(), handle_cli_osp_show(), handle_cli_realtime_pgsql_status(), handle_cli_refresh(), handle_cli_reload(), handle_cli_rtcp_set_debug(), handle_cli_rtcp_set_stats(), handle_cli_rtp_set_debug(), handle_cli_show_sqlite_status(), handle_cli_sqlite_show_tables(), handle_cli_status(), handle_cli_stun_set_debug(), handle_cli_submit(), handle_cli_transcoder_show(), handle_cli_udptl_set_debug(), handle_cli_ulimit(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_core_reload(), handle_core_set_debug_channel(), handle_core_show_image_formats(), handle_debug_dialplan(), handle_load(), handle_logger_mute(), handle_logger_set_level(), handle_manager_reload(), handle_manager_show_settings(), handle_mandebug(), handle_mfcr2_call_files(), handle_mfcr2_set_debug(), handle_mfcr2_show_channels(), handle_mgcp_audit_endpoint(), handle_mgcp_set_debug(), handle_mgcp_show_endpoints(), handle_minivm_list_templates(), handle_minivm_show_users(), handle_minivm_show_zones(), handle_modlist(), handle_nodebugchan_deprecated(), handle_orig(), handle_parkedcalls(), handle_pri_debug(), handle_pri_destroy_span(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_channels(), handle_pri_show_span(), handle_pri_show_spans(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_reload(), handle_queue_remove_member(), handle_queue_reset(), handle_queue_rule_show(), handle_queue_set_member_penalty(), handle_redirect(), handle_restart_gracefully(), handle_restart_now(), handle_restart_when_convenient(), handle_set_chanvar(), handle_set_extenpatternmatchnew(), handle_set_global(), handle_show_application(), handle_show_calendar(), handle_show_chanvar(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_hint(), handle_show_http(), handle_show_version_files(), handle_showcalls(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_showuptime(), handle_skinny_reload(), handle_skinny_reset(), handle_skinny_set_debug(), handle_skinny_show_lines(), handle_skinny_show_settings(), handle_softhangup(), handle_stop_gracefully(), handle_stop_now(), handle_stop_when_convenient(), handle_unload(), handle_unset_extenpatternmatchnew(), handle_verbose(), handle_version(), handle_voicemail_reload(), handle_voicemail_show_users(), handle_voicemail_show_zones(), iax_show_provisioning(), jingle_show_channels(), locals_show(), meetme_cmd_helper(), meetme_kick_cmd(), meetme_lock_cmd(), meetme_mute_cmd(), meetme_show_cmd(), orig_app(), orig_exten(), pktccops_debug(), pktccops_gatedel(), pktccops_gateset(), show_codec_n(), show_codecs(), sip_cli_notify(), sip_do_debug(), sip_do_debug_ip(), sip_prune_realtime(), sip_set_history(), sip_show_channel(), sip_show_channels(), sip_show_channelstats(), sip_show_history(), sip_show_inuse(), sip_show_objects(), sip_show_registry(), sip_show_settings(), sip_show_tcp(), sip_show_user(), sip_show_users(), sip_unregister(), timing_test(), unistim_do_debug(), unistim_info(), unistim_reload(), and unistim_sp().

#define CLI_SUCCESS   (char *)RESULT_SUCCESS

Definition at line 43 of file cli.h.

Referenced by __queues_show(), __say_cli_init(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), agent_logoff_cmd(), agents_show(), agents_show_online(), ais_clm_show_members(), ais_evt_show_event_channels(), aji_cli_create_collection(), aji_cli_create_leafnode(), aji_cli_delete_pubsub_node(), aji_cli_list_pubsub_nodes(), aji_cli_purge_pubsub_nodes(), aji_do_reload(), aji_do_set_debug(), aji_show_clients(), alias_show(), aoc_cli_debug_enable(), cli_alias_passthrough(), cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), cli_console_sendtext(), cli_fax_set_debug(), cli_fax_show_capabilities(), cli_fax_show_session(), cli_fax_show_sessions(), cli_fax_show_settings(), cli_fax_show_stats(), cli_fax_show_version(), cli_list_available(), cli_list_devices(), cli_odbc_read(), cli_odbc_write(), cli_realtime_destroy(), cli_realtime_load(), cli_realtime_store(), cli_realtime_update(), cli_realtime_update2(), cli_tps_ping(), cli_tps_report(), console_active(), console_answer(), console_autoanswer(), console_boost(), console_cmd(), console_dial(), console_do_answer(), console_flash(), console_hangup(), console_mute(), console_sendtext(), console_transfer(), dahdi_destroy_channel(), dahdi_restart_cmd(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_show_status(), dahdi_show_version(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_flush(), dundi_set_debug(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peer(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), dundi_store_history(), event_dump_cache(), group_show_channels(), gtalk_show_channels(), handle_abort_shutdown(), handle_bang(), handle_cc_kill(), handle_cc_status(), handle_chanlist(), handle_clear_profile(), handle_cli_ael_reload(), handle_cli_ael_set_debug(), handle_cli_agi_add_cmd(), handle_cli_agi_debug(), handle_cli_agi_dump_html(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_cli_config_list(), handle_cli_config_reload(), handle_cli_core_show_channeltype(), handle_cli_core_show_channeltypes(), handle_cli_core_show_config_mappings(), handle_cli_core_show_file_formats(), handle_cli_core_show_translation(), handle_cli_data_get(), handle_cli_data_show_providers(), handle_cli_database_del(), handle_cli_database_deltree(), handle_cli_database_get(), handle_cli_database_put(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_devstate_change(), handle_cli_devstate_list(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_ignorepat(), handle_cli_dialplan_add_include(), handle_cli_dialplan_reload(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_remove_ignorepat(), handle_cli_dialplan_remove_include(), handle_cli_dialplan_save(), handle_cli_file_convert(), handle_cli_h323_cycle_gk(), handle_cli_h323_hangup(), handle_cli_h323_reload(), handle_cli_h323_set_debug(), handle_cli_h323_set_trace(), handle_cli_h323_show_tokens(), handle_cli_h323_show_version(), handle_cli_iax2_provision(), handle_cli_iax2_prune_realtime(), handle_cli_iax2_reload(), handle_cli_iax2_set_debug(), handle_cli_iax2_set_debug_jb(), handle_cli_iax2_set_debug_trunk(), handle_cli_iax2_set_mtu(), handle_cli_iax2_show_cache(), handle_cli_iax2_show_callno_limits(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_firmware(), handle_cli_iax2_show_netstats(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_peers(), handle_cli_iax2_show_registry(), handle_cli_iax2_show_stats(), handle_cli_iax2_show_threads(), handle_cli_iax2_show_users(), handle_cli_iax2_test_losspct(), handle_cli_iax2_unregister(), handle_cli_indication_add(), handle_cli_indication_remove(), handle_cli_indication_show(), handle_cli_keys_init(), handle_cli_keys_show(), handle_cli_misdn_port_block(), handle_cli_misdn_port_down(), handle_cli_misdn_port_unblock(), handle_cli_misdn_port_up(), handle_cli_misdn_reload(), handle_cli_misdn_restart_pid(), handle_cli_misdn_restart_port(), handle_cli_misdn_send_digit(), handle_cli_misdn_send_display(), handle_cli_misdn_send_facility(), handle_cli_misdn_send_restart(), handle_cli_misdn_set_crypt_debug(), handle_cli_misdn_set_debug(), handle_cli_misdn_set_tics(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_config(), handle_cli_misdn_show_port(), handle_cli_misdn_show_ports_stats(), handle_cli_misdn_show_stacks(), handle_cli_misdn_toggle_echocancel(), handle_cli_mixmonitor(), handle_cli_moh_reload(), handle_cli_moh_show_classes(), handle_cli_moh_show_files(), handle_cli_odbc_show(), handle_cli_osp_show(), handle_cli_realtime_pgsql_status(), handle_cli_refresh(), handle_cli_reload(), handle_cli_reload_permissions(), handle_cli_rtcp_set_debug(), handle_cli_rtcp_set_stats(), handle_cli_rtp_set_debug(), handle_cli_show_permissions(), handle_cli_show_sqlite_status(), handle_cli_sqlite_show_tables(), handle_cli_status(), handle_cli_stun_set_debug(), handle_cli_submit(), handle_cli_transcoder_show(), handle_cli_udptl_set_debug(), handle_cli_ulimit(), handle_cli_wait_fullybooted(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_core_reload(), handle_core_set_debug_channel(), handle_core_show_image_formats(), handle_dahdi_show_cadences(), handle_debug_dialplan(), handle_dump_sched(), handle_feature_show(), handle_features_reload(), handle_help(), handle_load(), handle_logger_mute(), handle_logger_reload(), handle_logger_rotate(), handle_logger_set_level(), handle_logger_show_channels(), handle_manager_reload(), handle_manager_show_settings(), handle_mandebug(), handle_mfcr2_call_files(), handle_mfcr2_set_blocked(), handle_mfcr2_set_debug(), handle_mfcr2_set_idle(), handle_mfcr2_show_channels(), handle_mfcr2_show_variants(), handle_mfcr2_version(), handle_mgcp_audit_endpoint(), handle_mgcp_set_debug(), handle_mgcp_show_endpoints(), handle_minivm_list_templates(), handle_minivm_reload(), handle_minivm_show_settings(), handle_minivm_show_stats(), handle_minivm_show_users(), handle_minivm_show_zones(), handle_modlist(), handle_parkedcalls(), handle_pri_debug(), handle_pri_destroy_span(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_channels(), handle_pri_show_debug(), handle_pri_show_span(), handle_pri_show_spans(), handle_pri_version(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_reload(), handle_queue_remove_member(), handle_queue_reset(), handle_queue_rule_show(), handle_queue_set_member_penalty(), handle_redirect(), handle_reload(), handle_restart_gracefully(), handle_restart_now(), handle_restart_when_convenient(), handle_set_chanvar(), handle_set_extenpatternmatchnew(), handle_set_global(), handle_show_application(), handle_show_applications(), handle_show_calendar(), handle_show_calendars(), handle_show_chanvar(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_globals(), handle_show_hint(), handle_show_hints(), handle_show_http(), handle_show_profile(), handle_show_settings(), handle_show_switches(), handle_show_sysinfo(), handle_show_threads(), handle_show_version_files(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_showmancmds(), handle_showmanconn(), handle_showmaneventq(), handle_showuptime(), handle_skinny_reload(), handle_skinny_reset(), handle_skinny_set_debug(), handle_skinny_show_settings(), handle_softhangup(), handle_stop_gracefully(), handle_stop_now(), handle_stop_when_convenient(), handle_unload(), handle_unset_extenpatternmatchnew(), handle_verbose(), handle_version(), handle_voicemail_reload(), handle_voicemail_show_users(), handle_voicemail_show_zones(), help1(), help_workhorse(), iax_show_provisioning(), jingle_do_reload(), jingle_show_channels(), locals_show(), meetme_cmd_helper(), meetme_show_cmd(), mgcp_reload(), orig_app(), orig_exten(), pktccops_debug(), pktccops_gatedel(), pktccops_gateset(), pktccops_show_cmtses(), pktccops_show_gates(), pktccops_show_pools(), realtime_ldap_status(), rtcp_do_debug_ip(), rtp_do_debug_ip(), show_codec_n(), show_codecs(), show_license(), show_users_realtime(), show_warranty(), sip_cli_notify(), sip_do_debug(), sip_do_debug_ip(), sip_do_debug_peer(), sip_prune_realtime(), sip_reload(), sip_set_history(), sip_show_channel(), sip_show_channels(), sip_show_channelstats(), sip_show_domains(), sip_show_history(), sip_show_inuse(), sip_show_mwi(), sip_show_objects(), sip_show_registry(), sip_show_sched(), sip_show_settings(), sip_show_tcp(), sip_show_user(), sip_show_users(), sip_unregister(), sla_show_stations(), sla_show_trunks(), spandsp_fax_cli_show_capabilities(), spandsp_fax_cli_show_session(), spandsp_fax_cli_show_settings(), spandsp_fax_cli_show_stats(), timing_test(), unistim_do_debug(), unistim_info(), unistim_reload(), and unistim_sp().

#define ESS (   x)    ((x) == 1 ? "" : "s")

In many cases we need to print singular or plural words depending on a count. This macro helps us e.g. printf("we have %d object%s", n, ESS(n));

Definition at line 58 of file cli.h.

Referenced by cli_realtime_destroy(), cli_realtime_update(), cli_realtime_update2(), group_show_channels(), handle_chanlist(), handle_cli_status(), handle_parkedcalls(), handle_showcalls(), print_uptimestr(), and sip_show_channels().

#define RESULT_SUCCESS   0

Definition at line 39 of file cli.h.

Referenced by __iax2_show_peers(), agi_handle_command(), cli_fax_show_session(), dahdi_destroy_channel(), dahdi_destroy_channel_bynum(), do_monitor(), handle_answer(), handle_autohangup(), handle_channelstatus(), handle_controlstreamfile(), handle_dbdel(), handle_dbdeltree(), handle_dbget(), handle_dbput(), handle_getdata(), handle_getoption(), handle_getvariable(), handle_getvariablefull(), handle_gosub(), handle_hangup(), handle_noop(), handle_queue_pause_member(), handle_queue_set_member_penalty(), handle_recordfile(), handle_recvchar(), handle_recvtext(), handle_sayalpha(), handle_saydate(), handle_saydatetime(), handle_saydigits(), handle_saynumber(), handle_sayphonetic(), handle_saytime(), handle_sendimage(), handle_sendtext(), handle_setcallerid(), handle_setcontext(), handle_setextension(), handle_setmusic(), handle_setpriority(), handle_setvariable(), handle_showcalls(), handle_speechactivategrammar(), handle_speechcreate(), handle_speechdeactivategrammar(), handle_speechdestroy(), handle_speechloadgrammar(), handle_speechrecognize(), handle_speechset(), handle_speechunloadgrammar(), handle_streamfile(), handle_tddmode(), handle_verbose(), handle_waitfordigit(), locals_show(), logger_reload(), manager_data_get(), manager_iax2_show_netstats(), manager_iax2_show_peer_list(), manager_list_voicemail_users(), manager_parking_status(), manager_queue_rule_show(), manager_queues_show(), manager_queues_status(), manager_queues_summary(), set_member_paused(), and set_member_penalty().

Enumeration Type Documentation

calling arguments for new-style handlers.

Enumerator
CLI_INIT 
CLI_GENERATE 
CLI_HANDLER 

Definition at line 145 of file cli.h.

145  {
146  CLI_INIT = -2, /* return the usage string */
147  CLI_GENERATE = -3, /* behave as 'generator', remap argv to struct ast_cli_args */
148  CLI_HANDLER = -4, /* run the normal handler */
149 };
Definition: cli.h:146

Function Documentation

void ast_cli ( int  fd,
const char *  fmt,
  ... 
)

Definition at line 105 of file cli.c.

References ast_carefulwrite(), AST_CLI_INITLEN, AST_DYNSTR_BUILD_FAILED, ast_str_buffer(), ast_str_set_va(), ast_str_strlen(), and ast_str_thread_get().

Referenced by __iax2_show_peers(), __say_cli_init(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), _sip_show_peers_one(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), agent_logoff_cmd(), agents_show(), agents_show_online(), ais_clm_show_members(), ais_evt_show_event_channels(), aji_cli_create_collection(), aji_cli_create_leafnode(), aji_cli_delete_pubsub_node(), aji_cli_list_pubsub_nodes(), aji_cli_purge_pubsub_nodes(), aji_do_reload(), aji_do_set_debug(), aji_show_buddies(), aji_show_clients(), alias_show(), aoc_cli_debug_enable(), ast_cli_command_full(), ast_cli_netstats(), ast_console_toggle_mute(), cc_cli_output_status(), cc_cli_print_monitor_stats(), channel_set_debug(), cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), cli_console_sendtext(), cli_fax_set_debug(), cli_fax_show_capabilities(), cli_fax_show_session(), cli_fax_show_sessions(), cli_fax_show_settings(), cli_fax_show_stats(), cli_fax_show_version(), cli_list_available(), cli_list_devices(), cli_match_char_tree(), cli_odbc_read(), cli_odbc_write(), cli_realtime_destroy(), cli_realtime_load(), cli_realtime_store(), cli_realtime_update(), cli_realtime_update2(), cli_tps_ping(), cli_tps_report(), console_active(), console_answer(), console_autoanswer(), console_boost(), console_cmd(), console_dial(), console_do_answer(), console_flash(), console_hangup(), console_mute(), console_sendtext(), console_transfer(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_show_status(), dahdi_show_version(), data_provider_print_cli(), data_result_print_cli(), data_result_print_cli_node(), db_show_cb(), db_showkey_cb(), dialog_dump_func(), do_print(), dump_raw_ie(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_flush(), dundi_set_debug(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peer(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), dundi_store_history(), event_dump_cache(), event_dump_cli(), group_show_channels(), gtalk_show_channels(), handle_chanlist(), handle_cli_agi_add_cmd(), handle_cli_agi_debug(), handle_cli_agi_dump_html(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_cli_config_list(), handle_cli_core_show_channeltype(), handle_cli_core_show_channeltypes(), handle_cli_core_show_config_mappings(), handle_cli_core_show_file_formats(), handle_cli_core_show_translation(), handle_cli_database_del(), handle_cli_database_deltree(), handle_cli_database_get(), handle_cli_database_put(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_devstate_change(), handle_cli_devstate_list(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_ignorepat(), handle_cli_dialplan_add_include(), handle_cli_dialplan_reload(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_remove_ignorepat(), handle_cli_dialplan_remove_include(), handle_cli_dialplan_save(), handle_cli_file_convert(), handle_cli_h323_set_debug(), handle_cli_h323_set_trace(), handle_cli_iax2_provision(), handle_cli_iax2_prune_realtime(), handle_cli_iax2_set_debug(), handle_cli_iax2_set_debug_jb(), handle_cli_iax2_set_debug_trunk(), handle_cli_iax2_set_mtu(), handle_cli_iax2_show_cache(), handle_cli_iax2_show_callno_limits(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_firmware(), handle_cli_iax2_show_netstats(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_registry(), handle_cli_iax2_show_stats(), handle_cli_iax2_show_threads(), handle_cli_iax2_show_users(), handle_cli_iax2_unregister(), handle_cli_indication_show(), handle_cli_keys_show(), handle_cli_misdn_reload(), handle_cli_misdn_send_digit(), handle_cli_misdn_send_display(), handle_cli_misdn_set_debug(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_config(), handle_cli_misdn_show_port(), handle_cli_misdn_show_ports_stats(), handle_cli_misdn_show_stacks(), handle_cli_misdn_toggle_echocancel(), handle_cli_mixmonitor(), handle_cli_moh_show_classes(), handle_cli_moh_show_files(), handle_cli_odbc_show(), handle_cli_osp_show(), handle_cli_realtime_pgsql_cache(), handle_cli_realtime_pgsql_status(), handle_cli_refresh(), handle_cli_rtcp_set_debug(), handle_cli_rtcp_set_stats(), handle_cli_rtp_set_debug(), handle_cli_show_permissions(), handle_cli_show_sqlite_status(), handle_cli_sqlite_show_tables(), handle_cli_status(), handle_cli_stun_set_debug(), handle_cli_submit(), handle_cli_transcoder_show(), handle_cli_udptl_set_debug(), handle_cli_ulimit(), handle_cli_wait_fullybooted(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_core_set_debug_channel(), handle_core_show_image_formats(), handle_dahdi_show_cadences(), handle_debug_dialplan(), handle_feature_show(), handle_help(), handle_load(), handle_logger_reload(), handle_logger_rotate(), handle_logger_set_level(), handle_logger_show_channels(), handle_manager_show_settings(), handle_mandebug(), handle_mfcr2_call_files(), handle_mfcr2_set_blocked(), handle_mfcr2_set_debug(), handle_mfcr2_set_idle(), handle_mfcr2_show_channels(), handle_mfcr2_show_variants(), handle_mfcr2_version(), handle_mgcp_audit_endpoint(), handle_mgcp_set_debug(), handle_mgcp_show_endpoints(), handle_minivm_list_templates(), handle_minivm_reload(), handle_minivm_show_settings(), handle_minivm_show_stats(), handle_minivm_show_users(), handle_minivm_show_zones(), handle_modlist(), handle_parkedcalls(), handle_pri_debug(), handle_pri_destroy_span(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_debug(), handle_pri_show_span(), handle_pri_version(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_remove_member(), handle_queue_rule_show(), handle_queue_set_member_penalty(), handle_redirect(), handle_reload(), handle_restart_when_convenient(), handle_set_chanvar(), handle_set_extenpatternmatchnew(), handle_set_global(), handle_show_application(), handle_show_applications(), handle_show_calendar(), handle_show_calendars(), handle_show_chanvar(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_globals(), handle_show_hint(), handle_show_hints(), handle_show_http(), handle_show_profile(), handle_show_settings(), handle_show_switches(), handle_show_sysinfo(), handle_show_threads(), handle_show_version_files(), handle_showcalls(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_showmancmds(), handle_showmanconn(), handle_showmaneventq(), handle_skinny_set_debug(), handle_skinny_show_settings(), handle_softhangup(), handle_stop_when_convenient(), handle_unload(), handle_unset_extenpatternmatchnew(), handle_verbose(), handle_version(), handle_voicemail_reload(), handle_voicemail_show_users(), handle_voicemail_show_zones(), help1(), help_workhorse(), iax_show_provisioning(), jingle_show_channels(), locals_show(), meetme_show_cmd(), modlist_modentry(), orig_app(), orig_exten(), peer_dump_func(), pktccops_debug(), pktccops_gatedel(), pktccops_gateset(), pktccops_show_cmtses(), pktccops_show_gates(), pktccops_show_pools(), print_app_docs(), print_bc_info(), print_cel_sub(), print_codec_to_cli(), print_group(), print_stats_cb(), print_uptimestr(), realtime_ldap_status(), rtcp_do_debug_ip(), rtp_do_debug_ip(), show_channels_cb(), show_chanstats_cb(), show_codec_n(), show_codecs(), show_config_description(), show_debug_helper(), show_dialplan_helper(), show_license(), show_users_realtime(), show_warranty(), sig_pri_cli_show_channels(), sig_pri_cli_show_channels_header(), sig_pri_cli_show_span(), sig_pri_cli_show_spans(), sip_cli_notify(), sip_do_debug(), sip_do_debug_ip(), sip_do_debug_peer(), sip_prune_realtime(), sip_set_history(), sip_show_channel(), sip_show_channels(), sip_show_channelstats(), sip_show_domains(), sip_show_history(), sip_show_inuse(), sip_show_mwi(), sip_show_objects(), sip_show_registry(), sip_show_sched(), sip_show_settings(), sip_show_tcp(), sip_show_user(), sip_show_users(), sip_unregister(), sla_show_stations(), sla_show_trunks(), spandsp_fax_cli_show_capabilities(), spandsp_fax_cli_show_session(), spandsp_fax_cli_show_stats(), timing_test(), unistim_do_debug(), unistim_info(), and unistim_sp().

106 {
107  int res;
108  struct ast_str *buf;
109  va_list ap;
110 
112  return;
113 
114  va_start(ap, fmt);
115  res = ast_str_set_va(&buf, 0, fmt, ap);
116  va_end(ap);
117 
118  if (res != AST_DYNSTR_BUILD_FAILED) {
119  ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
120  }
121 }
int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
Try to write string, but wait no more than ms milliseconds before timing out.
Definition: utils.c:1328
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition: strings.h:792
#define AST_CLI_INITLEN
Initial buffer size for resulting strings in ast_cli()
Definition: cli.c:103
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:669
static struct ast_threadstorage ast_cli_buf
Definition: cli.c:100
int ast_cli_command_full ( int  uid,
int  gid,
int  fd,
const char *  s 
)

Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions.

Parameters
uidUser ID that is trying to run the command.
gidGroup ID that is trying to run the command.
fdpipe
sincoming string
Return values
0on success
-1on failure

Definition at line 2530 of file cli.c.

References args, ast_atomic_fetchadd_int(), ast_cli(), ast_free, ast_join(), AST_MAX_ARGS, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_FAILURE, CLI_HANDLER, cli_has_permissions(), CLI_SHOWUSAGE, ast_cli_args::fd, find_best(), find_cli(), ast_cli_entry::handler, ast_cli_entry::inuse, parse_args(), S_OR, and ast_cli_entry::usage.

Referenced by ast_cli_command_multiple_full().

2531 {
2532  const char *args[AST_MAX_ARGS + 1];
2533  struct ast_cli_entry *e;
2534  int x;
2535  char *duplicate = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL);
2536  char tmp[AST_MAX_ARGS + 1];
2537  char *retval = NULL;
2538  struct ast_cli_args a = {
2539  .fd = fd, .argc = x, .argv = args+1 };
2540 
2541  if (duplicate == NULL)
2542  return -1;
2543 
2544  if (x < 1) /* We need at least one entry, otherwise ignore */
2545  goto done;
2546 
2548  e = find_cli(args + 1, 0);
2549  if (e)
2552  if (e == NULL) {
2553  ast_cli(fd, "No such command '%s' (type 'core show help %s' for other possible commands)\n", s, find_best(args + 1));
2554  goto done;
2555  }
2556 
2557  ast_join(tmp, sizeof(tmp), args + 1);
2558  /* Check if the user has rights to run this command. */
2559  if (!cli_has_permissions(uid, gid, tmp)) {
2560  ast_cli(fd, "You don't have permissions to run '%s' command\n", tmp);
2561  ast_free(duplicate);
2562  return 0;
2563  }
2564 
2565  /*
2566  * Within the handler, argv[-1] contains a pointer to the ast_cli_entry.
2567  * Remember that the array returned by parse_args is NULL-terminated.
2568  */
2569  args[0] = (char *)e;
2570 
2571  retval = e->handler(e, CLI_HANDLER, &a);
2572 
2573  if (retval == CLI_SHOWUSAGE) {
2574  ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));
2575  } else {
2576  if (retval == CLI_FAILURE)
2577  ast_cli(fd, "Command '%s' failed.\n", s);
2578  }
2579  ast_atomic_fetchadd_int(&e->inuse, -1);
2580 done:
2581  ast_free(duplicate);
2582  return 0;
2583 }
static char * find_best(const char *argv[])
Definition: cli.c:2030
descriptor for a cli entry.
Definition: cli.h:165
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static int cli_has_permissions(int uid, int gid, const char *command)
Definition: cli.c:170
static char * parse_args(const char *s, int *argc, const char *argv[], int max, int *trailingwhitespace)
Definition: cli.c:2266
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
Definition: lock.h:603
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
int inuse
Definition: cli.h:173
const int fd
Definition: cli.h:153
static struct ast_cli_entry * find_cli(const char *const cmds[], int match_type)
Definition: cli.c:1986
char *(* handler)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: cli.h:181
static struct @350 args
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
#define ast_free(a)
Definition: astmm.h:97
#define AST_MAX_ARGS
Definition: cli.h:49
void ast_join(char *s, size_t len, const char *const w[])
Definition: utils.c:1690
const char * usage
Definition: cli.h:171
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
Definition: cli.c:225
int ast_cli_command_multiple_full ( int  uid,
int  gid,
int  fd,
size_t  size,
const char *  s 
)

Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions.

Parameters
uidUser ID that is trying to run the command.
gidGroup ID that is trying to run the command.
fdpipe
sizeis the total size of the string
sincoming string
Return values
numberof commands executed

Definition at line 2585 of file cli.c.

References ast_cli_command_full().

Referenced by netconsole().

2586 {
2587  char cmd[512];
2588  int x, y = 0, count = 0;
2589 
2590  for (x = 0; x < size; x++) {
2591  cmd[y] = s[x];
2592  y++;
2593  if (s[x] == '\0') {
2594  ast_cli_command_full(uid, gid, fd, cmd);
2595  y = 0;
2596  count++;
2597  }
2598  }
2599  return count;
2600 }
const int fd
Definition: cli.h:153
int ast_cli_command_full(int uid, int gid, int fd, const char *s)
Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run th...
Definition: cli.c:2530
char* ast_cli_complete ( const char *  word,
const char *const  choices[],
int  pos 
)

Helper function to generate cli entries from a NULL-terminated array. Returns the n-th matching entry from the array, or NULL if not found. Can be used to implement generate() for static entries as below (in this example we complete the word in position 2):

char *my_generate(const char *line, const char *word, int pos, int n)
{
static const char * const choices[] = { "one", "two", "three", NULL };
if (pos == 2)
return ast_cli_complete(word, choices, n);
else
return NULL;
}

Definition at line 1535 of file cli.c.

References ast_strdup, ast_strlen_zero(), and len().

Referenced by event_dump_cache(), handle_cc_kill(), handle_cli_core_show_translation(), handle_cli_devstate_change(), handle_cli_iax2_prune_realtime(), handle_orig(), handle_show_applications(), and sip_prune_realtime().

1536 {
1537  int i, which = 0, len;
1538  len = ast_strlen_zero(word) ? 0 : strlen(word);
1539 
1540  for (i = 0; choices[i]; i++) {
1541  if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
1542  return ast_strdup(choices[i]);
1543  }
1544  return NULL;
1545 }
#define ast_strdup(a)
Definition: astmm.h:109
Definition: ael.tab.c:203
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char** ast_cli_completion_matches ( const char *  ,
const char *   
)

Generates a NULL-terminated array of strings that 1) begin with the string in the second parameter, and 2) are valid in a command after the string in the first parameter.

The first entry (offset 0) of the result is the longest common substring in the results, useful to extend the string that has been completed. Subsequent entries are all possible values, followed by a NULL. All strings and the array itself are malloc'ed and must be freed by the caller.

Definition at line 2368 of file cli.c.

References ast_cli_generator(), ast_copy_string(), ast_free, ast_malloc, ast_realloc, and destroy_match_list().

Referenced by cli_complete(), and handle_commandmatchesarray().

2369 {
2370  char **match_list = NULL, *retstr, *prevstr;
2371  char **new_list;
2372  size_t match_list_len, max_equal, which, i;
2373  int matches = 0;
2374 
2375  /* leave entry 0 free for the longest common substring */
2376  match_list_len = 1;
2377  while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
2378  if (matches + 1 >= match_list_len) {
2379  match_list_len <<= 1;
2380  new_list = ast_realloc(match_list, match_list_len * sizeof(*match_list));
2381  if (!new_list) {
2382  destroy_match_list(match_list, matches);
2383  return NULL;
2384  }
2385  match_list = new_list;
2386  }
2387  match_list[++matches] = retstr;
2388  }
2389 
2390  if (!match_list) {
2391  return match_list; /* NULL */
2392  }
2393 
2394  /* Find the longest substring that is common to all results
2395  * (it is a candidate for completion), and store a copy in entry 0.
2396  */
2397  prevstr = match_list[1];
2398  max_equal = strlen(prevstr);
2399  for (which = 2; which <= matches; which++) {
2400  for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
2401  continue;
2402  max_equal = i;
2403  }
2404 
2405  retstr = ast_malloc(max_equal + 1);
2406  if (!retstr) {
2407  destroy_match_list(match_list, matches);
2408  return NULL;
2409  }
2410  ast_copy_string(retstr, match_list[1], max_equal + 1);
2411  match_list[0] = retstr;
2412 
2413  /* ensure that the array is NULL terminated */
2414  if (matches + 1 >= match_list_len) {
2415  new_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list));
2416  if (!new_list) {
2417  ast_free(retstr);
2418  destroy_match_list(match_list, matches);
2419  return NULL;
2420  }
2421  match_list = new_list;
2422  }
2423  match_list[matches + 1] = NULL;
2424 
2425  return match_list;
2426 }
char * text
Definition: app_queue.c:1091
Definition: ael.tab.c:203
#define ast_free(a)
Definition: astmm.h:97
char * ast_cli_generator(const char *, const char *, int)
Readline madness Useful for readline, that&#39;s about it.
Definition: cli.c:2525
static void destroy_match_list(char **match_list, int matches)
Definition: cli.c:2356
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define ast_realloc(a, b)
Definition: astmm.h:103
#define ast_malloc(a)
Definition: astmm.h:91
char* ast_cli_generator ( const char *  ,
const char *  ,
int   
)

Readline madness Useful for readline, that's about it.

Return values
0on success
-1on failure

Definition at line 2525 of file cli.c.

References __ast_cli_generator().

Referenced by ast_cli_completion_matches(), ast_cli_generatornummatches(), cli_alias_passthrough(), and handle_cli_check_permissions().

2526 {
2527  return __ast_cli_generator(text, word, state, 1);
2528 }
char * text
Definition: app_queue.c:1091
Definition: ael.tab.c:203
static char * __ast_cli_generator(const char *text, const char *word, int state, int lock)
Definition: cli.c:2442
int ast_cli_generatornummatches ( const char *  ,
const char *   
)

Return the number of unique matches for the generator.

Definition at line 2339 of file cli.c.

References ast_cli_generator(), and ast_free.

Referenced by handle_commandnummatches().

2340 {
2341  int matches = 0, i = 0;
2342  char *buf = NULL, *oldbuf = NULL;
2343 
2344  while ((buf = ast_cli_generator(text, word, i++))) {
2345  if (!oldbuf || strcmp(buf,oldbuf))
2346  matches++;
2347  if (oldbuf)
2348  ast_free(oldbuf);
2349  oldbuf = buf;
2350  }
2351  if (oldbuf)
2352  ast_free(oldbuf);
2353  return matches;
2354 }
char * text
Definition: app_queue.c:1091
Definition: ael.tab.c:203
#define ast_free(a)
Definition: astmm.h:97
char * ast_cli_generator(const char *, const char *, int)
Readline madness Useful for readline, that&#39;s about it.
Definition: cli.c:2525
int ast_cli_register ( struct ast_cli_entry e)

Registers a command or an array of commands.

Parameters
ewhich cli entry to register. Register your own command
Return values
0on success
-1on failure

Definition at line 2159 of file cli.c.

References __ast_cli_register().

Referenced by ast_cdr_engine_init(), ast_cel_engine_init(), ast_cli_register_multiple(), dnsmgr_init(), do_reload(), load_config(), and load_module().

2160 {
2161  return __ast_cli_register(e, NULL);
2162 }
static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
Definition: cli.c:2082
int ast_cli_register_multiple ( struct ast_cli_entry e,
int  len 
)

Register multiple commands.

Parameters
epointer to first cli entry to register
lennumber of entries to register

Definition at line 2167 of file cli.c.

References ast_cli_register(), and len().

Referenced by __ast_register_translator(), __init_manager(), ast_ais_clm_load_module(), ast_ais_evt_load_module(), ast_aoc_cli_init(), ast_builtins_init(), ast_cc_init(), ast_channels_init(), ast_data_init(), ast_event_init(), ast_features_init(), ast_file_init(), ast_http_init(), ast_image_init(), ast_indications_init(), ast_stun_init(), ast_test_init(), ast_timing_init(), ast_tps_init(), ast_udptl_init(), ast_utils_init(), astdb_init(), astobj2_init(), crypto_init(), iax_provision_init(), init_framer(), init_logger(), load_module(), load_pbx(), main(), and register_config_cli().

2168 {
2169  int i, res = 0;
2170 
2171  for (i = 0; i < len; i++)
2172  res |= ast_cli_register(e + i);
2173 
2174  return res;
2175 }
int ast_cli_register(struct ast_cli_entry *e)
Registers a command or an array of commands.
Definition: cli.c:2159
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_cli_unregister ( struct ast_cli_entry e)

Unregisters a command or an array of commands.

Parameters
ewhich cli entry to unregister Unregister your own command. You must pass a completed ast_cli_entry structure
Returns
0

Definition at line 2153 of file cli.c.

References __ast_cli_unregister().

Referenced by alias_unregister_cb(), ast_cel_engine_term(), ast_cli_unregister_multiple(), cdr_engine_shutdown(), dnsmgr_shutdown(), do_reload(), load_module(), and unload_module().

2154 {
2155  return __ast_cli_unregister(e, NULL);
2156 }
static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *ed)
Definition: cli.c:2060
int ast_cli_unregister_multiple ( struct ast_cli_entry e,
int  len 
)

Unregister multiple commands.

Parameters
epointer to first cli entry to unregister
lennumber of entries to unregister

Definition at line 2177 of file cli.c.

References ast_cli_unregister(), and len().

Referenced by __unload_module(), aoc_shutdown(), ast_ais_clm_unload_module(), astdb_shutdown(), astobj2_cleanup(), cc_shutdown(), channels_shutdown(), cli_shutdown(), close_logger(), config_shutdown(), data_shutdown(), event_shutdown(), features_shutdown(), file_shutdown(), framer_shutdown(), http_shutdown(), iax_provision_unload(), image_shutdown(), indications_shutdown(), load_module(), main_atexit(), manager_shutdown(), stun_shutdown(), timing_shutdown(), tps_shutdown(), udptl_shutdown(), unload_module(), and unload_pbx().

2178 {
2179  int i, res = 0;
2180 
2181  for (i = 0; i < len; i++)
2182  res |= ast_cli_unregister(e + i);
2183 
2184  return res;
2185 }
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
Definition: cli.c:2153
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char* ast_complete_channels ( const char *  line,
const char *  word,
int  pos,
int  state,
int  rpos 
)

Command completion for the list of active channels.

This can be called from a CLI command completion function that wants to complete from the list of active channels. 'rpos' is the required position in the command. This function will return NULL immediately if 'rpos' is not the same as the current position, 'pos'.

Definition at line 1547 of file cli.c.

References ast_channel_iterator_all_new(), ast_channel_iterator_by_name_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_strdup, ast_strlen_zero(), and ast_channel::name.

Referenced by complete_ch(), handle_cli_agi_add_cmd(), handle_cli_mixmonitor(), handle_core_set_debug_channel(), handle_redirect(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), and handle_softhangup().

1548 {
1549  struct ast_channel *c = NULL;
1550  int which = 0;
1551  char notfound = '\0';
1552  char *ret = &notfound; /* so NULL can break the loop */
1553  struct ast_channel_iterator *iter;
1554 
1555  if (pos != rpos) {
1556  return NULL;
1557  }
1558 
1559  if (ast_strlen_zero(word)) {
1561  } else {
1562  iter = ast_channel_iterator_by_name_new(word, strlen(word));
1563  }
1564 
1565  if (!iter) {
1566  return NULL;
1567  }
1568 
1569  while (ret == &notfound && (c = ast_channel_iterator_next(iter))) {
1570  if (++which > state) {
1571  ast_channel_lock(c);
1572  ret = ast_strdup(c->name);
1573  ast_channel_unlock(c);
1574  }
1575  ast_channel_unref(c);
1576  }
1577 
1579 
1580  return ret == &notfound ? NULL : ret;
1581 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1715
#define ast_strdup(a)
Definition: astmm.h:109
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
Definition: ael.tab.c:203
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const ast_string_field name
Definition: channel.h:787
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct ast_channel_iterator * ast_channel_iterator_by_name_new(const char *name, size_t name_len)
Create a new channel iterator based on name.
Definition: channel.c:1696
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1649
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1701