static unsigned int telnet_open_listen(unsigned int i) { char *vhost = NULL; char *msg; unsigned int rc; ir_sockaddr_union_t listenaddr; updatecontext(); vhost = irlist_get_nth(&gdata.telnet_vhost, i); if (vhost == NULL) return 1; rc = open_listen(0, &listenaddr, &(telnet_listen[i]), gdata.telnet_port, 1, 0, vhost); if (rc != 0) return 1; telnet_family[i] = listenaddr.sa.sa_family; msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &listenaddr.sa); ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "Telnet SERVER waiting for connection on %s", msg); mydelete(msg); return 0; }
/* handle transfer ip events */ void t_perform(int changesec, int changequartersec) { transfer *tr; unsigned int i, j; updatecontext(); if (changequartersec) { for (tr = irlist_get_head(&gdata.trans); tr; tr = irlist_get_next(tr)) { if (tr->nomax) continue; if (tr->maxspeed <= 0) continue; tr->tx_bucket += tr->maxspeed * (1024 / 4); tr->tx_bucket = min2(tr->tx_bucket, MAX_TRANSFER_TX_BURST_SIZE * tr->maxspeed * 1024); } } i = j = select_starting_transfer(); /* first: do from cur to end */ for (tr = irlist_get_nth(&gdata.trans, i); tr; tr = irlist_get_next(tr)) { if (tr->tr_status != TRANSFER_STATUS_SENDING) continue; /*----- look for transfer some ----- send at least once a second, or more if necessary */ if (changequartersec || FD_ISSET(tr->con.clientsocket, &gdata.writeset)) { gnetwork = &(gdata.networks[tr->net]); t_transfersome(tr); } } /* second: do from begin to cur-1 */ for (tr = irlist_get_head(&gdata.trans); tr && j; tr = irlist_get_next(tr), --j) { if (tr->tr_status != TRANSFER_STATUS_SENDING) continue; /*----- look for transfer some ----- send at least once a second, or more if necessary */ if (changequartersec || FD_ISSET(tr->con.clientsocket, &gdata.writeset)) { gnetwork = &(gdata.networks[tr->net]); t_transfersome(tr); } } tr = irlist_get_head(&gdata.trans); while(tr) { gnetwork = &(gdata.networks[tr->net]); /*----- look for listen->connected ----- */ if (tr->tr_status == TRANSFER_STATUS_LISTENING) { if (FD_ISSET(tr->con.listensocket, &gdata.readset)) { t_check_new_connection(tr); tr = irlist_get_next(tr); continue; } /*----- look for listen reminders ----- */ if (changesec) { if (tr->reminded == 0) { if ((gdata.curtime - tr->con.lastcontact) >= 30) t_remind(tr); } if (tr->reminded == 1) { if ((gdata.curtime - tr->con.lastcontact) >= 90) t_remind(tr); } if (tr->reminded == 2) { if ((gdata.curtime - tr->con.lastcontact) >= 150) t_remind(tr); } } } if (tr->tr_status == TRANSFER_STATUS_CONNECTING) { if (FD_ISSET(tr->con.clientsocket, &gdata.writeset)) t_connected(tr); } /*----- look for junk to read ----- */ if ((tr->tr_status == TRANSFER_STATUS_SENDING) || (tr->tr_status == TRANSFER_STATUS_WAITING)) { if (FD_ISSET(tr->con.clientsocket, &gdata.readset)) t_readjunk(tr); } /*----- look for done flushed status ----- */ if (tr->tr_status == TRANSFER_STATUS_WAITING) { t_flushed(tr); } if (changesec) { /*----- look for lost transfers ----- */ if (tr->tr_status != TRANSFER_STATUS_DONE) { t_istimeout(tr); } /*----- look for finished transfers ----- */ if (tr->tr_status == TRANSFER_STATUS_DONE) { char *trnick; trnick = tr->nick; mydelete(tr->caps_nick); mydelete(tr->hostname); mydelete(tr->con.localaddr); mydelete(tr->con.remoteaddr); mydelete(tr->country); tr = irlist_delete(&gdata.trans, tr); if (!gdata.exiting && irlist_size(&gdata.mainqueue) && (irlist_size(&gdata.trans) < gdata.slotsmax)) { check_idle_queue(0); send_from_queue(0, 0, trnick); } mydelete(trnick); continue; } } tr = irlist_get_next(tr); } gnetwork = NULL; }
void parseconsole(void) { static char console_escape_seq[maxtextlengthshort]; unsigned char tempbuffa[INPUT_BUFFER_LENGTH]; int length; unsigned int linelength; userinput ui; unsigned int i, j; updatecontext(); bzero(console_escape_seq, sizeof(console_escape_seq)); if (is_fd_readable(fileno(stdin))) { memset(tempbuffa, 0, INPUT_BUFFER_LENGTH); length = read (fileno(stdin), &tempbuffa, INPUT_BUFFER_LENGTH); if (length < 1) { outerror(OUTERROR_TYPE_CRASH,"read from stdin failed: %s",(length<0) ? strerror(errno) : "EOF!"); } linelength = strlen(gdata.console_input_line); for (i=0; i<(unsigned int)length; i++) { if (console_escape_seq[0] != '\0') { size_t esc_len = strlen(console_escape_seq); if (esc_len < (maxtextlengthshort-2)) { console_escape_seq[esc_len]=tempbuffa[i]; esc_len++; if (((tempbuffa[i] >= 'a') && (tempbuffa[i] <= 'z')) || ((tempbuffa[i] >= 'A') && (tempbuffa[i] <= 'Z'))) { /* process sequence */ if (console_escape_seq[1] == '[') { if (console_escape_seq[esc_len-1] == 'A') { /* up */ int count; if (esc_len > 3) { count=atoi(&console_escape_seq[2]); } else { count=1; } while(count--) { if (gdata.console_history_offset) { gdata.console_history_offset--; strncpy(gdata.console_input_line, irlist_get_nth(&gdata.console_history, gdata.console_history_offset), INPUT_BUFFER_LENGTH-1); linelength = strlen(gdata.console_input_line); gdata.curcol = linelength; } } } else if (console_escape_seq[esc_len-1] == 'B') { /* down */ int count; if (esc_len > 3) { count=atoi(&console_escape_seq[2]); } else { count=1; } while(count--) { gdata.console_history_offset++; if (gdata.console_history_offset < irlist_size(&gdata.console_history)) { strncpy(gdata.console_input_line, irlist_get_nth(&gdata.console_history, gdata.console_history_offset), INPUT_BUFFER_LENGTH-1); linelength = strlen(gdata.console_input_line); gdata.curcol = linelength; } else { memset(gdata.console_input_line, 0, INPUT_BUFFER_LENGTH); linelength = 0; gdata.curcol = 0; } gdata.console_history_offset = min2(gdata.console_history_offset,irlist_size(&gdata.console_history)); } } else if (console_escape_seq[esc_len-1] == 'C') { /* right */ int count; if (esc_len > 3) { count=atoi(&console_escape_seq[2]); } else { count=1; } gdata.curcol += count; if (gdata.curcol > linelength) gdata.curcol = linelength; } else if (console_escape_seq[esc_len-1] == 'D') { /* left */ unsigned int count; if (esc_len > 3) { count=atoi(&console_escape_seq[2]); } else { count=1; } if (count <= gdata.curcol) gdata.curcol -= count; } /* else ignore */ } /* else ignore */ memset(console_escape_seq, 0, maxtextlengthshort); } } else { /* sequence is too long, ignore */ memset(console_escape_seq, 0, maxtextlengthshort); } } else if (tempbuffa[i] == '\x1b') { console_escape_seq[0]=tempbuffa[i]; } else if ((tempbuffa[i] == '\t') && gdata.console_input_line[0]) { if (!gdata.attop) gototop(); j = u_expand_command(); gdata.curcol += j; linelength += j; } else if (tempbuffa[i] == '\n') { char *hist; hist = irlist_get_tail(&gdata.console_history); if ((!hist || strcmp(hist,gdata.console_input_line)) && gdata.console_input_line[0]) { hist = irlist_add(&gdata.console_history, linelength+1); strncpy(hist, gdata.console_input_line, linelength); } if (irlist_size(&gdata.console_history) > MAX_HISTORY_SIZE) { irlist_delete(&gdata.console_history, irlist_get_head(&gdata.console_history)); } gdata.console_history_offset = irlist_size(&gdata.console_history); if (!gdata.attop) gototop(); u_fillwith_console(&ui,gdata.console_input_line); u_parseit(&ui); gdata.curcol=0; memset(gdata.console_input_line, 0, INPUT_BUFFER_LENGTH); } else if (isprintable(tempbuffa[i])) { if (linelength < (INPUT_BUFFER_LENGTH-2)) { for (j=linelength; j>gdata.curcol; j--) { gdata.console_input_line[j] = gdata.console_input_line[j-1]; } gdata.console_input_line[gdata.curcol]=tempbuffa[i]; gdata.curcol++; linelength++; } } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VINTR]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VQUIT]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VERASE]) { if (gdata.curcol) { for (j=gdata.curcol-1; j<linelength; j++) { gdata.console_input_line[j] = gdata.console_input_line[j+1]; } linelength--; gdata.console_input_line[linelength] = '\0'; gdata.curcol--; } } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VWERASE]) { while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] == ' ')) { for (j=gdata.curcol-1; j<linelength; j++) { gdata.console_input_line[j] = gdata.console_input_line[j+1]; } linelength--; gdata.console_input_line[linelength] = '\0'; gdata.curcol--; } while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] != ' ')) { for (j=gdata.curcol-1; j<linelength; j++) { gdata.console_input_line[j] = gdata.console_input_line[j+1]; } linelength--; gdata.console_input_line[linelength] = '\0'; gdata.curcol--; } while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] == ' ')) { for (j=gdata.curcol-1; j<linelength; j++) { gdata.console_input_line[j] = gdata.console_input_line[j+1]; } linelength--; gdata.console_input_line[linelength] = '\0'; gdata.curcol--; } } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VKILL]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VEOF]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSTART]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSTOP]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSUSP]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VLNEXT]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VREPRINT]) { } else if (tempbuffa[i] == gdata.startup_tio.c_cc[VDISCARD]) { } else if (tempbuffa[i] == '\x01') /* Ctrl-A */ { gdata.curcol = 0; } else if (tempbuffa[i] == '\x05') /* Ctrl-E */ { gdata.curcol = linelength; } } drawbot(); } }