📄 console.c
字号:
challenge[i] = (int)(256.0*rand()/(RAND_MAX+1.0));SHA1(challenge, 128, callpkt.cryptinfo.challenge_sha1);call.cryptinfo.type = callpkt.cryptinfo.type;cr_set_key(pass2);cr_encrypt(challenge, 128, callpkt.cryptinfo.challenge, &os);}memcpy(&call.cryptinfo, &callpkt.cryptinfo, sizeof(callpkt.cryptinfo));#endifqueuepacket(&call.cssq, PKT_TYPE_CALL, (char *)&callpkt, sizeof(callpkt));SET_BIT(call.state, CALL_STATE_CONNECTED|CALL_STATE_CALLING);}static void cmd_copyright(int ARGC, char **ARGV){fputs("Intercom - Real-Time audio communication utility.\n\n""Copyright (C) 2001-2003 Shane Wegner\n\n""\n""This program is free software; you can redistribute it and/or\n""modify it under the terms of version 2 of the GNU General Public\n""License as published by the Free Software Foundation.\n""\n""This program is distributed in the hope that it will be useful,\n""but WITHOUT ANY WARRANTY; without even the implied warranty of\n""MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n""GNU General Public License for more details.\n""\n""A copy of version 2 of the GNU General Public License is\n""distributed with Intercom under the filename COPYING.\n""\n""For license details use the command: \"copyright\"\n\n", stdout);}static void cmd_exec(int ARGC, char **ARGV){if (ARGC != 2)fprintf(stderr, _("Usage: %s <command>\n"), ARGV[0]);elsesystem(ARGV[1]);}static void cmd_hangup(int ARGC, char **ARGV){if (ARGC > 1)fprintf(stderr, _("Usage: '%s'.\n"), ARGV[0]);else if (!TEST_BIT(call.state, CALL_STATE_CONNECTED))fprintf(stderr, _("%s: No call is currently in progress.\n"), ARGV[0]);else {puts(_("Hanging up."));if (TEST_BIT(call.state, CALL_STATE_WFRANSWER)) {/* A call was requested and rejected so send back a response packet *//* before hanging up. */if (fcntl(call.csock, F_SETFL, O_RDWR) == -1)perror("fcntl");else {struct pkt_callresponse pkt;size_t buffsize;char *buff;pkt.responsecode = CALLRESPONSE_DENY;queuepacket(&call.cssq, PKT_TYPE_CALLRESPONSE, (char *)&pkt, sizeof(pkt));buffsize = iob_buffsize(&call.cssq);buff = alloca(buffsize);iob_read(&call.cssq, buff, buffsize);write(call.csock, buff, buffsize);} /* endif fcntl */} /* endif rejected */if (TEST_BIT(call.state, CALL_STATE_INCALL))hk_trigger(hk_hangup_lc);closecall();}}/* cmd_help is defined below */static void cmd_help(int, char **);static void cmd_hook(int ARGC, char **ARGV){struct option long_options[] = {{"help", no_argument, NULL, 'h'},{"verbose", no_argument, NULL, 'v'},{NULL, 0, NULL, 0}};int o;int verbose = 0;optind = 0;while ((o = getopt_long(ARGC, ARGV, "hv", long_options, (int *)0)) != EOF)switch(o) {case 'h':printf(_("Valid usage: %s [options]\n""%s [options] add <type> <cmd>\n""%s clearid <id>\n""%s cleartype <type>\n""%s clearall\n""\nOptions:\n""-h, --help\tDisplay this help information\n""-v, --verbose\tVerbose output\n""\n"), ARGV[0], ARGV[0], ARGV[0], ARGV[0], ARGV[0]);return;case 'v':verbose = 1;break;default:fprintf(stderr, _("%s: Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;};if ((ARGC - optind) == 0) { /* list */struct hook_info *h;puts(_("Currently defined event-hooks:"));for (h = hook_list; h != NULL; h = h->next) {printf("Id: %d, Type: ", h->id);switch(h->type) {case hk_call_incoming:fputs("call_incoming", stdout);break;case hk_call_outgoing:fputs("call_outgoing", stdout);break;case hk_call_connect:fputs("call_connect", stdout);break;case hk_hangup_lc:fputs("hangup_lc", stdout);break;case hk_hangup_rmt:fputs("hangup_rmt", stdout);break;case hk_sighup:fputs("sighup", stdout);break;default:assert(0);};printf(", Cmd: '%s'\n", h->cmd);}putchar('\n');}else if (!strcasecmp(ARGV[optind], "add")) {hk_type_t type;if ((ARGC - optind) != 3) {fprintf(stderr, _("%s: Invalid usage. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;}if ((type = hk_strtotype(ARGV[optind+1])) == hk_invalid) {fprintf(stderr, _("%s: Invalid event-hook type.\n"), ARGV[0]);return;}hk_add(type, ARGV[optind + 2]);} else if (!strcasecmp(ARGV[optind], "clearall")) {if ((ARGC - optind) != 1) {fprintf(stderr, _("%s: Invalid usage. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;}o = hk_clearall();if (verbose)printf(_("%s: Deleted %d hooks\n"), ARGV[0], o);} else if (!strcasecmp(ARGV[optind], "clearid")) {int id;if ((ARGC - optind) != 2) {fprintf(stderr, _("%s: Invalid usage. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;}id = atoi(ARGV[optind + 1]);o = hk_clear(id);if (verbose)printf(_("%s: Deleted %d hooks\n"), ARGV[0], o);} else if (!strcasecmp(ARGV[optind], "cleartype")) {hk_type_t type;if ((ARGC - optind) != 2) {fprintf(stderr, _("%s: Invalid usage. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;}if ((type = hk_strtotype(ARGV[optind + 1])) == hk_invalid) {fprintf(stderr, "%s: Invalid event-hook type.\n", ARGV[0]);return;}o = hk_cleartype(type);if (verbose)printf(_("%s: Deleted %d hooks\n"), ARGV[0], o);} elsefprintf(stderr,_("%s: Invalid hook command. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);}static void cmd_if(int ARGC, char **ARGV){struct option long_options[]={{"help", no_argument, NULL, 'h'},{"verbose", no_argument, NULL, 'v'},{NULL, 0, NULL, 0}};int o;int verbose = 0;int my_code = 0;const char *op = "=";const char *my_cmd, *my_action, *my_elaction = NULL;int do_action = 0;optind = 0;while ((o = getopt_long(ARGC, ARGV, "c:hv", long_options, (int *)0)) != EOF)switch(o) {case 'h':printf(_("Usage: %s [options] <command> [<op> <exitcode> | && | ||] <action> else <action>\n\n""Options\n""-h, --help\tDisplay this help information\n""-v, --verbose\tTurn on verbose output\n\n""Valid values for <op> are =, !=, <, >, <=, and >=.\n\n"),ARGV[0]);return;case 'v':verbose = 1;break;default:fprintf(stderr, _("Try '%s --help' for a usage summary.\n"), ARGV[0]);return;};if ((ARGC - optind) < 2) {fprintf(stderr, _("%s: Too few arguments. Try '%s --help' for a usage summary."),ARGV[0], ARGV[0]);return;}my_cmd = ARGV[optind++];if (!strcmp(ARGV[optind], "=") || !strcmp(ARGV[optind], "!=") ||!strcmp(ARGV[optind], "<") || !strcmp(ARGV[optind], ">") ||!strcmp(ARGV[optind], "<=") || !strcmp(ARGV[optind], ">=")) {op = ARGV[optind++];if (!(ARGC - optind)) {fprintf(stderr, _("%s: Parse error near '%s'\n"),ARGV[0], ARGV[optind-1]);return;}my_code = atoi(ARGV[optind++]);} else if (!strcmp(ARGV[optind], "&&"))optind++; /* default */else if (!strcmp(ARGV[optind], "||")) {op = "!=";optind++;}if (!(ARGC - optind)) {fprintf(stderr, _("%s: Parse error near '%s'\n"),ARGV[0], ARGV[optind-1]);return;}my_action = ARGV[optind++];if ((ARGC - optind)) {if (strcasecmp(ARGV[optind++], "else")) {fprintf(stderr, _("%s: Parse error near '%s'.\n"), ARGV[0], ARGV[optind-1]);return;}if (!(ARGC - optind)) {fprintf(stderr, _("%s: Parse error near '%s'\n"),ARGV[0], ARGV[optind-1]);return;}my_elaction = ARGV[optind++];}if ((o = system(my_cmd)) == -1) {fprintf(stderr, _("%s: system() failed: %s\n"),ARGV[0], strerror(errno));return;}o = WEXITSTATUS(o);if (o == 127) {fprintf(stderr, _("%s: System command failed.\n"), ARGV[0]);return;}if (verbose)printf(_("%s: Command exited with status %d comparing to %d with %s\n"),ARGV[0], o, my_code, op);if (!strcasecmp(op, "="))do_action = (o == my_code);if (!strcasecmp(op, "!="))do_action = (o != my_code);if (!strcasecmp(op, "<"))do_action = (o < my_code);if (!strcasecmp(op, ">"))do_action = (o > my_code);if (!strcasecmp(op, "<="))do_action = (o <= my_code);if (!strcasecmp(op, ">="))do_action = (o >= my_code);if (do_action) {if (verbose)printf(_("%s: Running '%s'\n"), ARGV[0], my_action);processline(0, my_action);} else if (my_elaction) {if (verbose)printf(_("%s: Running '%s'\n"), ARGV[0], my_elaction);processline(0, my_elaction);}}static void cmd_message(int ARGC, char **ARGV){char *msgdata, *msgp;size_t i, msglen = 0;if (ARGC == 1) {fprintf(stderr, _("%s: No message to send.\n"), ARGV[0]);return;}if (!TEST_BIT(call.state, CALL_STATE_CONNECTED)) {fprintf(stderr, _("%s: There is no connection currently established.\n"), ARGV[0]);return;}for (i = 1; i < ARGC; i++)msglen += strlen(ARGV[i]) + 1;msgdata = alloca(msglen);msgp = msgdata;for (i = 1; i < ARGC; i++)msgp += sprintf(msgp, "%s ", ARGV[i]);queuepacket(&call.cssq, PKT_TYPE_USRTEXT, msgdata, msglen-1);puts(_("Your message has been queued."));}static void cmd_quit(int ARGC, char ** ARGV){if (ARGC > 1)fprintf(stderr, _("Usage: '%s'.\n"), ARGV[0]);elsedone = 1;console_done();}static void cmd_read(int ARGC, char **ARGV){static const struct option long_options[]={{"help", no_argument, NULL, 'h'},{"silent", no_argument, NULL, 's'},{NULL, 0, NULL, 0}};int silent = 0;size_t i, l;char buff[4096];char *startp;FILE *f;optind = 0;while ((i = getopt_long(ARGC, ARGV, "hs", long_options, (int *)0)) != EOF) {switch(i) {case 'h':printf(_("Usage: %s [options] <filename> [<filename> ...]\n\n""Valid options:\n""-h, --help\tOutput this help information\n""-s, --silent\tDo not output error or status messages\n""\n"), ARGV[0]);return;case 's':silent = 1;break;default:fprintf(stderr, _("Try '%s --help' for a usage summary.\n"), ARGV[0]);return;}}if (!(ARGC - optind)) {if (!silent)fprintf(stderr, _("%s: No file(s) were specified.\n"), ARGV[0]);return;}for (i = optind; i < ARGC; i++) {if ((f = fopen(ARGV[i], "r")) == NULL) {if (!silent)fprintf(stderr, _("fopen(%s): %s\n"), ARGV[i], strerror(errno));continue;}while(fgets(buff, 4096, f) != NULL) {l = strlen(buff) - 1;while(buff[l] == '\r' || buff[l] == '\n')buff[l--] = 0;for (startp = buff; *startp == ' ' || *startp == '\t'; startp++);if (*startp != '#')processline(0, startp);}fclose(f);}}static void escapestr(const char *from, char *to){const char *fp;char *tp = to;for (fp = from; *fp; fp++) {if (*fp == '"' || *fp == '\\') {*tp = '\\';tp++;}*tp = *fp;tp++;}*tp = 0;}static void cmd_save(int ARGC, char **ARGV){static const struct option long_options[]={{"aliases", no_argument, NULL, 'a'},{"file", required_argument, NULL, 'f'},{"help", no_argument, NULL, 'h'},{"hooks", no_argument, NULL, 'H'},{"variables", no_argument, NULL, 'v'},{NULL, 0, NULL, 0}};char *filename = NULL, *key = NULL, *val = NULL;FILE *f;int o;int novariable = 0, noalias = 0, nohooks = 0;struct alias *ap;struct hook_info *h;time_t ti;struct tm *tm;optind = 0;while ((o = getopt_long(ARGC, ARGV, "af:hv", long_options, (int *)0)) != EOF) {switch(o) {case 'a':novariable = 1;nohooks = 1;break;case 'f':filename = optarg;break;case 'h':printf(_("Usage: %s [options]\n\n""Valid options:\n""-a, --aliases\tOnly save aliases to rc-file\n""-f, --file\tSpecify where configuration data is to be written\n""-h, --help\tDisplay this help information\n""-H, --hooks\tOnly save event-hooks\n""-v, --variables\tONly save configuration variables to rc-file\n\n"),ARGV[0]);return;case 'H':noalias = 1;novariable = 1;break;break;case 'v':noalias = 1;nohooks = 1;break;default:fprintf(stderr, _("Try '%s --help' for a usage summary.\n"), ARGV[0]);return;}}if ((ARGC - optind) > 0) {fprintf(stderr, _("%s: Too many options specified. Try '%s --help' for a usage summary.\n"),ARGV[0], ARGV[0]);return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -