static int dowhoall(int fd) { char buf[100]; char *chatid, *userid, *channame; printchatline(_msg_chat_10); sprintf(genbuf, "[7m%-10s %-12s %-15s[m", _msg_chat_8, _msg_chat_9, _msg_chat_11); printchatline(genbuf); sprintf(genbuf, "%-10s %-12s %-15s", "------", "------", "------"); printchatline(genbuf); net_printf(fd, "WHOALL\r\n"); net_gets(fd, genbuf, sizeof(genbuf)); if (strncmp(genbuf, "+OK", 3)) return -1; do { net_gets(fd, buf, sizeof(buf)); if (buf[0] == '.') break; userid = strtok(buf, "\t"); chatid = strtok(NULL, "\t\r\n"); channame = strtok(NULL, "\t\r\n"); sprintf(genbuf, "%-10s %-12s %-15s", chatid, userid, channame); printchatline(genbuf); } while (buf[0] != '.'); return 0; }
static int dowho(char *channame, int fd) { char buf[100]; char chatid[80], userid[80], fromip[80]; int cnt = 0; char uline[200], pline[50]; net_printf(fd, "WHO\t%s\r\n", channame); net_gets(fd, genbuf, sizeof(genbuf)); if (strncmp(genbuf, "+OK", 3)) { printchatline(_msg_chat_44); return -1; } printchatline(_msg_chat_7); sprintf(buf, "[7m%-12s %-12s %-12s %-12s %-12s %-12s[m", _msg_chat_8, _msg_chat_9, _msg_chat_8, _msg_chat_9, _msg_chat_8, _msg_chat_9); printchatline(buf); sprintf(buf, "%-12s %-12s %-12s %-12s %-12s %-12s", "------", "------", "------", "------", "------", "------"); printchatline(buf); memset(uline, 0, sizeof(uline)); do { net_gets(fd, buf, sizeof(buf)); if (buf[0] == '.') break; sscanf(buf, "%s\t%s\t%s\r\n", userid, chatid, fromip); sprintf(pline, "[1;36;40m%-12s[m %-12s", chatid, userid); if (cnt < 2) strcat(pline, " "); strcat(uline, pline); if (++cnt == 3) { cnt = 0; printchatline(uline); memset(uline, 0, sizeof(uline)); } } while (buf[0] != '.'); if (cnt < 3) printchatline(uline); return 0; }
int CloseMailSocket(int ms) /* close socket to mail server */ { char buffer[STRLEN]; net_printf(ms, "QUIT\r\n"); net_gets(ms, buffer, sizeof(buffer)); close(ms); return 0; }
static int rtsp_read_line(SOCKET fd,char *p_buffer,int i_buffer) { char *psz = net_gets(fd); if(psz) strncpy(p_buffer,psz,i_buffer); else *p_buffer = 0; free(psz); return 0; }
/************************************************************** * 直接與 SMTP Port 連接 **************************************************************/ static int DirectSMTPMail(int ms, const char *fname, const char *from, const char *to, const char *title, const char *forward) { FILE *fp; char gbufTmp[512]; if (fname == NULL || *fname == '\0') return -1; if ((fp = fopen(fname, "r")) == NULL) return -1; sleep(1); /* lasehu: wait for mail server response */ net_printf(ms, "MAIL FROM:<%s>\r\n", from); if (!net_gets(ms, gbufTmp, sizeof(gbufTmp))) return -1; if (strncmp(gbufTmp, "250 ", 4)) return -1; net_printf(ms, "RCPT TO:<%s>\r\n", to); if (!net_gets(ms, gbufTmp, sizeof(gbufTmp))) return -1; if (strncmp(gbufTmp, "250 ", 4)) return -1; net_printf(ms, "DATA\r\n"); if (!net_gets(ms, gbufTmp, sizeof(gbufTmp))) return -1; if (strncmp(gbufTmp, "354 ", 4)) return -1; net_printf(ms, "From: %s\r\n", from); net_printf(ms, "To: %s\r\n", to); output_rfc2047_qp(gbufTmp, title, "BIG5"); net_printf(ms, "Subject: %s\r\n", gbufTmp); if (forward) /* lthuang */ net_printf(ms, "X-Forwarded-By: %s.bbs@%s", forward, myhostname); net_printf(ms, "Content-Type: text/plain; charset=BIG5\r\n"); output_rfc2047_qp(gbufTmp, BBSTITLE, "BIG5"); net_printf(ms, "X-Disclaimer: [%s]", gbufTmp); output_rfc2047_qp(gbufTmp, _msg_x_disclaimer, "BIG5"); net_printf(ms, " %s\r\n\r\n", gbufTmp); while (fgets(gbufTmp, sizeof(gbufTmp), fp)) { char *ptr; if ((ptr = strchr(gbufTmp, '\n')) != NULL) *ptr = '\0'; net_printf(ms, "%s\r\n", gbufTmp); } fclose(fp); net_printf(ms, "\r\n.\r\n"); if (!net_gets(ms, gbufTmp, sizeof(gbufTmp))) return -1; if (strncmp(gbufTmp, "250 ", 4)) return -1; net_printf(ms, "RSET\r\n"); if (!net_gets(ms, gbufTmp, sizeof(gbufTmp))) return -1; #ifdef BBSLOG_MAIL { time_t now; char timestr[20]; time(&now); strftime(timestr, sizeof(timestr), "%m/%d/%Y %X", localtime(&now)); sprintf(gbufTmp, "%s %-12.12s %s\n", timestr, from, to); append_record(PATH_MAILLOG, gbufTmp, strlen(gbufTmp)); } #endif return 0; }
static void dochatcommand(char *cmd) { char *para; strtok(cmd, " \n"); if ((para = strtok(NULL, "\n")) == NULL) para = cmd + strlen(cmd); if (*cmd == 'h') { printchatline(_msg_chat_41); printchatline(" /leave - Â÷¶}¥»ÀW¹D [/le]"); if (curuser.userlevel >= PERM_CLOAK) printchatline(" /cloak - Áô¨ [/cl]"); printchatline(_msg_chat_43); return; } else if (!strcmp(cmd, "who") || !strcmp(cmd, "w")) { dowho(para, ac); return; } else if (!strcmp(cmd, "ws") || !strcmp(cmd, "whoall")) { dowhoall(ac); return; } else if (!strcmp(cmd, "list") || !strcmp(cmd, "l")) { dolist(ac); return; } else if (!strcmp(cmd, "leave") || !strcmp(cmd, "le")) { net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD); } else if (!strcmp(cmd, "nopasswd") || !strcmp(cmd, "nps")) { net_printf(ac, "PASSWD\t%s\r\n", NOPASSWORD); } else if (!strcmp(cmd, "nick") || !strcmp(cmd, "n")) { fixchatid(para); net_printf(ac, "NICKNAME\t%s\r\n", para); net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) printchatline(genbuf + 5); else { xstrncpy(uinfo.chatid, para, sizeof(uinfo.chatid)); update_ulist(cutmp, &uinfo); /* set prompt */ strcpy(prompt, uinfo.chatid); strcat(prompt, ": "); prompt[SAYWORD_POINT] = '\0'; } return; } else if (!strcmp(cmd, "me")) { if (*para) { sprintf(genbuf, "*** %s ***", para); net_printf(ac, "SPEAK\t%s\r\n", genbuf); printchatline(genbuf); } else printchatline(_msg_chat_45); return; } else if (!strcmp(cmd, "pager") || !strcmp(cmd, "p")) { #if 1 add_io(0, 0); #endif toggle_pager(); printchatline(pagerstring(&uinfo)); #if 1 add_io(ac, 0); #endif return; } else if (!strcmp(cmd, "cloak") || !strcmp(cmd, "cl")) { if (HAS_PERM(PERM_CLOAK)) { net_printf(ac, "CLOAK\r\n"); net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) printchatline(genbuf + 5); else { uinfo.invisible = (uinfo.invisible) ? FALSE : TRUE; update_ulist(cutmp, &uinfo); if (!uinfo.invisible) printchatline("*** Cloak has been deactivated"); else printchatline("*** Cloak has been activated"); } } else printchatline("*** ERROR: unknown special chat command"); return; } else if (!strcmp(cmd, "clear") || !strcmp(cmd, "c")) { clear(); move(ECHATWIN, 0); outs("________________________________________________________________________________"); chat_line = 0; /* reset */ printchatline(_msg_chat_46); return; } else if (!strcmp(cmd, "ignore") || !strcmp(cmd, "i")) { if (*para) { if (strlen(para) >= IDLEN) para[IDLEN - 1] = '\0'; if (!cmp_wlist(iglist, para, strcmp)) { sprintf(genbuf, _msg_chat_37, para); printchatline(genbuf); add_wlist(&iglist, para, malloc_str); } } return; } else if (!strcmp(cmd, "unignore") || !strcmp(cmd, "ui")) { if (*para) { if (strlen(para) >= IDLEN) para[IDLEN - 1] = '\0'; if (cmp_wlist(iglist, para, strcmp)) { sprintf(genbuf, _msg_chat_36, para); printchatline(genbuf); cmpd_wlist(&iglist, para, strcmp, free); } } return; } else if (!strcmp(cmd, "j") || !strcmp(cmd, "join")) { char *para2; para = strtok(para, " \n"); if (!para) return; para2 = strtok(NULL, " \n"); if (!para2) net_printf(ac, "JOIN\t%s\t%s\r\n", para, NOPASSWORD); else net_printf(ac, "JOIN\t%s\t%s\r\n", para, para2); } else if (!strcmp(cmd, "m") || !strcmp(cmd, "msg")) { char *para2; para = strtok(para, " \n"); para2 = strtok(NULL, ""); if (!para || !para2) return; net_printf(ac, "MSG\t%s\t%s\r\n", para, para2); } else if (!strcmp(cmd, "t") || !strcmp(cmd, "topic")) { net_printf(ac, "TOPIC\t%s\r\n", para); } else if (!strcmp(cmd, "ps") || !strcmp(cmd, "passwd")) { net_printf(ac, "PASSWD\t%s\r\n", para); } else { printchatline("*** ERROR: unknown special chat command"); return; } net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) { genbuf[strlen(genbuf) - 1] = '\0'; printchatline(genbuf + 5); } }
int t_chat2() { int currchar; char inbuf[120]; BOOL page_pending = FALSE; int ch; char seedstr[STRLEN]; long seed; char rcvbuf[512]; int chatport; char *mycrypt(); if (check_page_perm() < 0) return C_FOOT; chatport = CHATPORT; #if 1 if (chatport == 0) chatport = 6177; #endif #if 0 #if defined(NSYSUBBS1) getdata(1, 0, _msg_chat_1, genbuf, 2, ECHONOSP); if (genbuf[0] == '2') chatport = CHATPORT + 1; #endif #endif /* initialize */ inbuf[0] = '\0'; currchar = 0; chat_line = 0; if (!getdata(1, 0, "Enter Chat id: ", mychatid, CHATIDLEN, ECHONOSP)) xstrncpy(mychatid, curuser.userid, CHATIDLEN); fixchatid(mychatid); if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0) { move(2, 0); outs(_msg_chat_3); refresh(); sprintf(genbuf, "bbschatd %d", chatport); outdoor(genbuf); sleep(2); if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0) { perror("connect failed"); pressreturn(); return C_FULL; } } /* receive ChatServer Hello Welcome VersionInfo */ net_gets(ac, genbuf, sizeof(genbuf)); /* receive Random Number for Checksum */ net_gets(ac, seedstr, sizeof(seedstr)); seed = atol(mycrypt(seedstr)); net_printf(ac, "USRID\t%s\t%ld\r\n", curuser.userid, seed); net_gets(ac, genbuf, sizeof(genbuf)); if (strncmp(genbuf, "+OK", 3)) /* lthuang */ { outs(_msg_chat_4); pressreturn(); return C_FULL; } uinfo.mode = CHATROOM; xstrncpy(uinfo.chatid, mychatid, sizeof(uinfo.chatid)); update_ulist(cutmp, &uinfo); /* set prompt */ strcpy(prompt, mychatid); strcat(prompt, ": "); prompt[SAYWORD_POINT] = '\0'; draw_chat_screen(); add_io(ac, 0); net_gets(ac, genbuf, sizeof(genbuf)); /* welcome !! */ genbuf[strlen(genbuf) - 1] = '\0'; printchatline(genbuf); #if 0 net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD); net_gets(ac, genbuf, sizeof(genbuf)); #endif if (strcmp(mychatid, curuser.userid)) { net_printf(ac, "NICKNAME\t%s\r\n", mychatid); net_gets(ac, genbuf, sizeof(genbuf)); } /* Chat Main */ while (1) { ch = getkey(); if (PLINE != CUR_PLINE) { draw_chat_screen(); continue; } if (talkrequest) page_pending = TRUE; if (page_pending) page_pending = servicepage(0); if (msqrequest) { add_io(0, 0); msqrequest = FALSE; msq_reply(); add_io(ac, 0); continue; } if (ch == I_OTHERDATA) { if (!net_gets(ac, rcvbuf, sizeof(rcvbuf))) break; rcvbuf[strlen(rcvbuf) - 1] = '\0'; /* lthuang */ if (rcvbuf[0] == '/') { char *p, *nick; if ((p = strchr(rcvbuf, '\t')) != NULL) { *p = '\0'; if (cmp_wlist(iglist, rcvbuf + 1, strcmp)) continue; nick = p + 1; if ((p = strchr(nick, '\t')) != NULL) { *p = '\0'; if (cmp_wlist(iglist, nick, strcmp)) continue; strcpy(genbuf, nick); strcat(genbuf, ": "); genbuf[SAYWORD_POINT] = '\0'; strcat(genbuf, ++p); printchatline(genbuf); } } } #if 0 else if (rcvbuf[0] == '*') { sprintf(genbuf, "[1;37m%s[0m", rcvbuf); printchatline(genbuf); } #endif else printchatline(rcvbuf); } else if (isprint2(ch)) { if (SAYWORD_POINT + currchar - 1 >= t_columns - 3) { bell(); continue; } inbuf[currchar++] = ch; inbuf[currchar] = '\0'; move(PLINE, SAYWORD_POINT + currchar - 1); outc(ch); } else if (ch == '\n' || ch == '\r') { char *p = inbuf; currchar = 0; while (*p != '\0' && isspace((int)(*p))) p++; if (*p == '\0') continue; if (inbuf[0] == '/') dochatcommand(inbuf + 1); else { net_printf(ac, "SPEAK\t%s\r\n", inbuf); sprintf(genbuf, "%s%s", prompt, inbuf); printchatline(genbuf); } inbuf[0] = '\0'; /* show prompt */ move(PLINE, 0); clrtoeol(); outs(prompt); } else if (ch == CTRL('H') || ch == '\177') { if (currchar == 0) { bell(); continue; } move(PLINE, SAYWORD_POINT + --currchar); outs(" "); inbuf[currchar] = '\0'; } else if (ch == CTRL('C') || ch == CTRL('D')) { net_printf(ac, "QUIT\r\n"); /* lthuang */ break; } else if (ch == CTRL('R')) { msq_reply(); continue; } else if (ch == CTRL('Q')) { add_io(0, 0); t_query(); add_io(ac, 0); continue; } move(PLINE, currchar + SAYWORD_POINT); } add_io(0, 0); close(ac); uinfo.chatid[0] = '\0'; update_ulist(cutmp, &uinfo); free_wlist(&iglist, free); return C_FULL; }
static int quh_cddb_in_open (st_quh_nfo_t * file) { int x = 0; char buf[MAXBUFSIZE]; int t = 0, n = 0; char buf2[MAXBUFSIZE]; char *p = NULL; st_http_header_t http_header; char http_header_s[NET_MAXHTTPHEADERSIZE]; if (!inited) { if (!quh_get_object_s (quh.filter_chain, QUH_OPTION)) quh_set_object_s (quh.filter_chain, QUH_OPTION, "http://freedb.freedb.org/~cddb/cddb.cgi"); #ifdef USE_TCP net = net_init (NET_TCP|NET_CLIENT, 5); #endif inited = 1; } *buf = 0; if (!file->indices) { strcpy (buf, "Failed: Input has no indices"); quh_set_object_s (quh.filter_chain, QUH_OUTPUT, buf); return 0; } for (x = 0; x < file->indices; x++) { // add to cddb_sum n += cddb_sum (file->index_pos[x] / file->channels / file->size / file->rate); if (x == 0) t = (file->raw_size / file->channels / file->size / file->rate) - (file->index_pos[x] / file->channels / file->size / file->rate) - ((file->index_pos[x] / file->channels / file->size / file->rate) % 60); } cddb_id = (n % 0xff) << 24 | t << 8 | file->indices; #ifdef USE_TCP net_open (net, cddb_host, 80); sprintf (buf, "%s%s?cmd=cddb+query+%08lx+%d+", cddb_host, cddb_uri, cddb_id, file->indices); for (x = 0; x < file->indices; x++) sprintf (strchr (buf, 0), "%ld+", (file->index_pos[x] / 2352) + 150); sprintf (strchr (buf, 0), "%ld&hello=anonymous+localhost+%s+%s&proto=6", ((file->raw_size / 2352) + 150) / 75, "Quh", QUH_VERSION_S); net_build_http_request (http_header_s, buf, "Quh", 0, NET_METHOD_GET, 0); net_write (net, http_header_s, strlen (http_header_s)); net_parse_http_response (&http_header, net); // before: classical 9b10f50b Wayne Marshall / Symphonie // after: classical+9b10f50b while (net_gets (net, buf, MAXBUFSIZE)) { // 200 classical 9e10cb0b Wayne Marshall / Organ Transcriptions if (!strncmp (buf, "200 ", 4)) { strtrim_s (buf, "200 ", NULL); p = strchr (buf, ' '); if (p) *p = '+'; p = strchr (buf, ' '); if (p) *p = 0; strncpy (buf2, buf, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0; break; } // 211 Found inexact matches, list follows (until terminating .') // classical 9b10f50b Wayne Marshall / Symphonie // . if (!strncmp (buf, "211 ", 4)) if (net_gets (net, buf, MAXBUFSIZE)) { p = strchr (buf, ' '); if (p) *p = '+'; p = strchr (buf, ' '); if (p) *p = 0; strncpy (buf2, buf, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0; break; } } // we don't use the http keep alive flag net_close (net); net_open (net, cddb_host, 80); sprintf (buf, "%s%s?cmd=cddb+read+%s&hello=anonymous+localhost+%s+%s&proto=6", cddb_host, cddb_uri, buf2, "Quh", QUH_VERSION_S); p = net_build_http_request (buf, "Quh", 0, NET_METHOD_GET, 0); net_write (net, p, strlen (p)); net_parse_http_response (net); x = 0; while (net_gets (net, buf, MAXBUFSIZE)) if (!strncmp (buf, "TTITLE", 6)) { sprintf (buf2, "TTITLE%d", x); p = (char *) get_property_from_string (buf, buf2, '=', '#'); if (p) strncpy (file->index_name[x], p, QUH_INDEX_NAME_LEN)[QUH_INDEX_NAME_LEN - 1] = 0; else *(file->index_name[x]) = 0; #ifdef DEBUG printf ("%s\n\n", file->index_name[x]); #endif x++; if (x == file->indices) break; } net_close (net); #endif // USE_TCP *buf = 0; sprintf (strchr (buf, 0), "DiscId: 0x%08lx\n", cddb_id); if (file->indices) for (x = 1 ; x < file->indices + 1; x++) { unsigned long len = (x < file->indices ? file->index_pos[x] : file->raw_size) - file->index_pos[x - 1]; sprintf (strchr (buf, 0), "%0*d:", misc_digits (QUH_MAXINDEX), x); sprintf (strchr (buf, 0), " %s", file->index_name[x - 1]); sprintf (strchr (buf, 0), "%s", quh_bytes_to_units (file, len, QUH_UNITS_CLOCK)); if (x < file->indices) strcat (buf, "\n"); } quh_set_object_s (quh.filter_chain, QUH_OUTPUT, buf); return 0; }