Changeset 5633
Add CLI-local commands and implement "?set prompt" and "?set events"
Comitted by:
mjagdis
Date:
Feb 14 2010 * 23:36 (about 1 year ago)
Affected files:
callweaver/trunk/corelib/callweaver.c (diff)
callweaver/trunk/corelib/console.c (diff)
callweaver/trunk/corelib/console.h (diff)
callweaver/trunk/corelib/manager.c (diff)
callweaver/trunk/corelib/callweaver.c (unified diff)
| r5631 | r5633 | |
|---|---|---|
| 1580 | 1580 | } |
| 1581 | 1581 | #endif |
| 1582 | 1582 | |
| 1583 | cw_registry_init(&clicmd_registry, 1024); | |
| 1584 | ||
| 1585 | /* The console commands are registered here so they will exist | |
| 1586 | * locally in remote consoles as well as in the core server. | |
| 1587 | * It is also worth noting that they are registered in the | |
| 1588 | * core server regardless of whether a built in console is | |
| 1589 | * enabled or not because command completion, help etc. are | |
| 1590 | * always handled on the server side. | |
| 1591 | */ | |
| 1592 | cw_console_cli_init(); | |
| 1593 | ||
| 1583 | 1594 | if (option_remote || option_exec) { |
| 1584 | 1595 | char *p; |
| 1585 | 1596 | |
| --- | --- | |
| 1716 | 1727 | cw_registry_init(&channel_registry, 1024); |
| 1717 | 1728 | cw_registry_init(&device_registry, 1024); |
| 1718 | 1729 | cw_registry_init(&cdrbe_registry, 64); |
| 1719 | cw_registry_init(&clicmd_registry, 1024); | |
| 1720 | 1730 | cw_registry_init(&config_engine_registry, 64); |
| 1721 | 1731 | cw_registry_init(&format_registry, 128); |
| 1722 | 1732 | cw_registry_init(&func_registry, 4096); |
callweaver/trunk/corelib/console.c (unified diff)
| r5632 | r5633 | |
|---|---|---|
| 645 | 645 | cw_safe_system(s+1); |
| 646 | 646 | else |
| 647 | 647 | cw_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh"); |
| 648 | } else if (s[0] == '@') { | |
| 649 | if (!strncmp(&s[1], "set prompt ", sizeof("set prompt ") - 1)) { | |
| 650 | set_prompt(&s[sizeof("set prompt ") - 1]); | |
| 651 | rl_set_prompt(prompt.data); | |
| 652 | } else | |
| 653 | fprintf(stderr, "unknown command: %s\n", s); | |
| 648 | } else if (s[0] == '?') { | |
| 649 | static struct cw_dynstr ds = CW_DYNSTR_INIT; | |
| 650 | ||
| 651 | cw_cli_command(&ds, s); | |
| 652 | fwrite(ds.data, 1, ds.used, stdout); | |
| 653 | cw_dynstr_reset(&ds); | |
| 654 | 654 | } else if (option_remote && (!strcasecmp(s, "quit") || !strcasecmp(s, "exit"))) { |
| 655 | 655 | console_cleanup(NULL); |
| 656 | 656 | exit(0); |
| --- | --- | |
| 924 | 924 | |
| 925 | 925 | return n; |
| 926 | 926 | } |
| 927 | ||
| 928 | ||
| 929 | /*----------------------------------------------------------------------------*/ | |
| 930 | ||
| 931 | ||
| 932 | static const char setprompt_help[] = | |
| 933 | "Usage: ?set prompt <prompt>\n" | |
| 934 | " Set the command prompt used when the console is ready to\n" | |
| 935 | " read a command. CallWeaver allows the prompt string to be\n" | |
| 936 | " customized using the following special formats:\n" | |
| 937 | " %%C* - reset colours and attributes to defaults\n" | |
| 938 | " %%C<fg> - set the foreground colour to colour <fg>\n" | |
| 939 | " %%C<fg>;<bg> - set the foreground and background colours\n" | |
| 940 | " to the given colour numbers\n" | |
| 941 | " %%C{fg=<fg>,bg=<bg>} - set the foreground and background colours to\n" | |
| 942 | " the given colour numbers or names\n" | |
| 943 | " the available colour numbers and names depend\n" | |
| 944 | " on the terminal used but for ANSI compliant\n" | |
| 945 | " terminals would be:\n" | |
| 946 | " 0/black, 1/red, 2/green, 3/yellow, 4/blue,\n" | |
| 947 | " 5/magenta, 6/cyan, 7/white\n" | |
| 948 | " %%C{attr,attr,...} - set the specified attributes\n" | |
| 949 | " note that attributes may be combined with the\n" | |
| 950 | " colour name specification above but not all\n" | |
| 951 | " combinations work on all terminals\n" | |
| 952 | " the attributes known are:\n" | |
| 953 | " altcharset, blink, bold, dim, invis,\n" | |
| 954 | " protect, reverse, standout, underline\n" | |
| 955 | " %%d - current date as YYYY-MM-DD\n" | |
| 956 | " %%H - short remote hostname\n" | |
| 957 | " %%h - full remote hostname\n" | |
| 958 | #ifdef linux | |
| 959 | " %%l<n> - load average\n" | |
| 960 | " n = 1 - 1 minute load average\n" | |
| 961 | " n = 2 - 5 minute load average\n" | |
| 962 | " n = 3 - 15 minute load average\n" | |
| 963 | #endif | |
| 964 | " %%t - time as HH:MM:SS\n" | |
| 965 | " %%# - '#' if this is the built in console\n" | |
| 966 | " '>' if this is a remote console\n" | |
| 967 | " %%%% - a single '%'\n"; | |
| 968 | ||
| 969 | static int setprompt_handler(struct cw_dynstr *ds_p, int argc, char *argv[]) | |
| 970 | { | |
| 971 | CW_UNUSED(ds_p); | |
| 972 | ||
| 973 | if (argc != 3) | |
| 974 | return RESULT_SHOWUSAGE; | |
| 975 | ||
| 976 | set_prompt(argv[2]); | |
| 977 | rl_set_prompt(prompt.data); | |
| 978 | ||
| 979 | return RESULT_SUCCESS; | |
| 980 | } | |
| 981 | ||
| 982 | ||
| 983 | static const char setevents_help[] = | |
| 984 | "Usage: ?set events <event>[,<event>...]\n" | |
| 985 | " Sets the events that this console is to receive.\n" | |
| 986 | " Events can be:\n" | |
| 987 | " error, warning, notice, verbose, event, dtmf, debug\n"; | |
| 988 | ||
| 989 | static int setevents_handler(struct cw_dynstr *ds_p, int argc, char *argv[]) | |
| 990 | { | |
| 991 | struct cw_dynstr ds = CW_DYNSTR_INIT; | |
| 992 | int i; | |
| 993 | ||
| 994 | CW_UNUSED(ds_p); | |
| 995 | ||
| 996 | if (argc < 3) | |
| 997 | return RESULT_SHOWUSAGE; | |
| 998 | ||
| 999 | cw_dynstr_printf(&ds, "Action: Events\r\nEventmask: %s", argv[2]); | |
| 1000 | for (i = 3; i < argc; i++) | |
| 1001 | cw_dynstr_printf(&ds, ",%s", argv[i]); | |
| 1002 | cw_dynstr_printf(&ds, "\r\n\r\n"); | |
| 1003 | ||
| 1004 | cw_write_all(console_sock, ds.data, ds.used); | |
| 1005 | read_message(console_sock, 1); | |
| 1006 | ||
| 1007 | return RESULT_SUCCESS; | |
| 1008 | } | |
| 1009 | ||
| 1010 | ||
| 1011 | static struct cw_clicmd builtins[] = { | |
| 1012 | { | |
| 1013 | .cmda = { "?set", "prompt", NULL }, | |
| 1014 | .handler = setprompt_handler, | |
| 1015 | .summary = "Set the prompt", | |
| 1016 | .usage = setprompt_help, | |
| 1017 | }, | |
| 1018 | { | |
| 1019 | .cmda = { "?set", "events", NULL }, | |
| 1020 | .handler = setevents_handler, | |
| 1021 | .summary = "Set the events to be logged to this console", | |
| 1022 | .usage = setevents_help, | |
| 1023 | }, | |
| 1024 | }; | |
| 1025 | ||
| 1026 | ||
| 1027 | void cw_console_cli_init(void) | |
| 1028 | { | |
| 1029 | cw_cli_register_multiple(builtins, arraysize(builtins)); | |
| 1030 | } |
callweaver/trunk/corelib/console.h (unified diff)
| r4309 | r5633 | |
|---|---|---|
| 18 | 18 | |
| 19 | 19 | extern void *console(void *data); |
| 20 | 20 | extern int console_oneshot(char *spec, char *cmd); |
| 21 | extern void cw_console_cli_init(void); |
callweaver/trunk/corelib/manager.c (unified diff)
| r5625 | r5633 | |
|---|---|---|
| 1101 | 1101 | |
| 1102 | 1102 | CW_UNUSED(sess); |
| 1103 | 1103 | |
| 1104 | if (cmd) { | |
| 1104 | if (cmd && *cmd != '?') { | |
| 1105 | 1105 | if ((msg = cw_manager_response("Follows", NULL))) { |
| 1106 | 1106 | msg->ds.used -= 2; |
| 1107 | 1107 |
![Home changeset 5633 [home]](/images/logo.png?1180520111)

RSS Feeds