home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B85.ZIP
/
NEWS.CPP
< prev
next >
Wrap
Text File
|
1998-01-03
|
58KB
|
2,148 lines
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <process.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <errno.h>
#include <fcntl.h>
#include <io.h>
#include <dos.h>
#include <share.h>
#include <dir.h>
#include <alloc.h>
#include <mem.h>
#include <sys\stat.h>
#include <math.h>
extern "C" {
#include "tcp.h"
}
#include "net.h"
#include "vardec.h"
#include "version.h"
#include "retcode.h"
#define SIZE_OF_EMULATOR 415
#define FILL_CHAR 0xFF
extern unsigned _stklen = 10240U;
#define SHARE_LEVEL 10
#define WAIT_TIME 10
#define TRIES 100
#define MT_DESQVIEW 0x01
#define MT_WINDOWS 0x02
#define MT_OS2 0x04
#define MT_NB 0x40
#define BIGSTR 2048
#define STRING 513
#define STR 129
#define WAIT_TIME 10
#define TRIES 100
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define NNTP_PORT 119
typedef struct {
tcp_Socket *sock;
} Mail_Socket;
configrec syscfg;
char *version = "Freeware PPP Project News Retrieval " VERSION;
static unsigned char _temp_buffer[STRING];
char POPNAME[25], POPDOMAIN[45];
char cur_path[STRING], cur_from[STRING], cur_subject[STRING], cur_replyto[STRING];
char cur_newsgroups[STRING], cur_message_ID[STRING], cur_organization[STRING];
char cur_articleid[STRING], cur_references[STRING], cur_lines[STR], cur_date[STRING];
static char maindir[MAXPATH], net_data[MAXPATH];
int instance, crossposts, newsrc_upd, binxpost, MOREINFO, multitasker = 0;
static int spooltodisk, NNTP_stat;
unsigned long cur_daten, reparticle, cur_numa, cur_first, cur_last;
unsigned short reply, sy;
static char NEWSNAME[STRING], NEWSPASS[STRING];
typedef struct {
char groupname[60];
unsigned long lastread;
char subtype[8];
} GROUPFILEREC;
GROUPFILEREC *grouprec;
int ngroups;
#define SOCK_READ_ERR(PROTOCOL) sock_err: \
switch (PROTOCOL##_stat) { \
case 1 : \
fprintf(stderr, "\n ! Session error : %s", \
sockerr(PROTOCOL##_sock->sock)); \
if (grouprec != NULL) write_groups(1); \
if (PROTOCOL##_sock->sock != NULL) \
farfree(PROTOCOL##_sock->sock); \
if (PROTOCOL##_sock != NULL) \
farfree(PROTOCOL##_sock); \
fcloseall(); \
cursor('R'); \
exit(EXIT_FAILURE); \
case -1: \
fprintf(stderr, "\n ! Timeout : %s", \
sockerr(PROTOCOL##_sock->sock)); \
if (grouprec != NULL) write_groups(1); \
if (PROTOCOL##_sock->sock != NULL) \
farfree(PROTOCOL##_sock->sock); \
if (PROTOCOL##_sock != NULL) \
farfree(PROTOCOL##_sock); \
fcloseall(); \
cursor('R'); \
exit(EXIT_FAILURE); \
} \
char *texth[] = {"th", "st", "nd", "rd"};
char *ordinal_text(int number)
{
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
number = 0;
return texth[number];
}
static unsigned cursize;
void cursor(int tmp)
{
union REGS inregs, outregs;
switch (toupper(tmp)) {
case 'S': /* Save */
inregs.h.ah = 3;
inregs.h.bh = 0;
int86(0x10, &inregs, &outregs);
cursize = outregs.x.cx;
break;
case 'R': /* Restore */
inregs.h.ah = 1;
inregs.x.cx = cursize;
int86(0x10, &inregs, &outregs);
break;
case 'H': /* Hide */
inregs.h.ah = 1;
inregs.h.ch = 0x20;
int86(0x10, &inregs, &outregs);
break;
case 'N': /* Normal */
inregs.h.ah = 1;
inregs.h.ch = 6;
inregs.h.cl = 7;
int86(0x10, &inregs, &outregs);
break;
}
}
void dv_pause(void)
{
__emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
}
void win_pause(void)
{
__emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
}
int get_dos_version(void)
{
_AX = 0x3000;
geninterrupt(0x21);
if (_AX % 256 >= 10) {
multitasker |= MT_OS2;
}
return (_AX);
}
int get_dv_version(void)
{
int v;
if (multitasker & MT_OS2)
return 0;
_AX = 0x2b01;
_CX = 0x4445;
_DX = 0x5351;
geninterrupt(0x21);
if (_AL == 0xff) {
return 0;
} else {
v = _BX;
multitasker |= MT_DESQVIEW;
return v;
}
}
int get_win_version(void)
{
int v = 0;
__emit__(0x55, 0x06, 0x53);
_AX = 0x352f;
geninterrupt(0x21);
_AX = _ES;
if (_AX | _BX) {
_AX = 0x1600;
geninterrupt(0x2f);
v = _AX;
if (v % 256 <= 1)
v = 0;
}
__emit__(0x5b, 0x07, 0x5d);
if (v != 0)
multitasker |= MT_WINDOWS;
return (v);
}
int get_nb_version(void)
{
_AX = 0;
geninterrupt(0x2A);
return (_AH);
}
void detect_multitask(void)
{
get_dos_version();
get_win_version();
get_dv_version();
if (multitasker < 2)
if (get_nb_version())
multitasker = MT_NB;
}
void giveup_timeslice(void)
{
if (multitasker) {
switch (multitasker) {
case 1:
case 3:
dv_pause();
break;
case 2:
case 4:
case 5:
case 6:
case 7:
win_pause();
break;
default:
break;
}
}
}
void output(char *fmt,...)
{
va_list v;
char s[255];
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, stderr);
}
void backline(void)
{
int i;
output(" ");
for (i = wherex(); i > 0; i--)
output("\b \b");
}
void cd_to(char *s)
{
char *s1;
int i, db;
s1 = s;
i = strlen(s1) - 1;
db = (s1[i] == '\\');
if (i == 0)
db = 0;
if ((i == 2) && (s1[1] == ':'))
db = 0;
if (db)
s1[i] = 0;
chdir(s1);
if (s[1] == ':')
setdisk(s[0] - 'A');
}
void get_dir(char *s, int be)
{
strcpy(s, "X:\\");
s[0] = 'A' + getdisk();
getcurdir(0, s + 3);
if (be) {
if (s[strlen(s) - 1] != '\\')
strcat(s, "\\");
}
}
int sh_write(int handle, void *buffer, unsigned long length)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buffer, (unsigned) length));
}
int sh_open(char *path, int file_access, unsigned fmode)
{
int handle, count, share;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
share = SH_DENYRW;
} else {
share = SH_DENYWR;
}
handle = open(path, file_access | share, fmode);
if (handle < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
handle = open(path, file_access | share, fmode);
while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
if (count % 2)
delay(WAIT_TIME);
else
giveup_timeslice();
count++;
handle = open(path, file_access | share, fmode);
}
}
}
return (handle);
}
int sh_open1(char *path, int access)
{
unsigned fmode;
fmode = 0;
if ((access & O_RDWR) || (access & O_WRONLY))
fmode |= S_IWRITE;
if ((access & O_RDWR) || (access & O_RDONLY))
fmode |= S_IREAD;
return (sh_open(path, access, fmode));
}
int sh_close(int f)
{
if (f != -1)
close(f);
return (-1);
}
int sh_read(int handle, void *buf, unsigned length)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, length));
}
long sh_lseek(int handle, long offset, int fromwhere)
{
if (handle == -1) {
return (-1L);
}
return (lseek(handle, offset, fromwhere));
}
FILE *fsh_open(char *path, char *fmode)
{
FILE *f;
int count, share, md, fd;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
share = SH_DENYWR;
md = 0;
if (((char *) _fstrchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) _fstrchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) _fstrchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) _fstrchr(fmode, '+')) != NULL) {
md &= ~O_RDONLY;
md |= O_RDWR;
share = SH_DENYRD;
}
fd = open(path, md | share, S_IREAD | S_IWRITE);
if (fd < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if ((access(path, 0)) != -1) {
delay(WAIT_TIME);
fd = open(path, md | share, S_IREAD | S_IWRITE);
while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
delay(WAIT_TIME);
count++;
fd = open(path, md | share, S_IREAD | S_IWRITE);
}
}
}
if (fd > 0) {
if (((char *) _fstrchr(fmode, 'a')) != NULL)
sh_lseek(fd, 0L, SEEK_END);
f = fdopen(fd, fmode);
if (!f) {
close(fd);
}
} else
f = 0;
return (f);
}
size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
{
if (stream == NULL) {
return (0);
}
return (fwrite(ptr, size, n, stream));
}
char *stristr(char *string, char *pattern)
{
char *pptr, *sptr, *start;
unsigned int slen, plen;
for (start = string, pptr = pattern, slen = strlen(string),
plen = strlen(pattern); slen >= plen; start++, slen--) {
while (toupper(*start) != toupper(*pattern)) {
start++;
slen--;
if (slen < plen)
return (NULL);
}
sptr = start;
pptr = pattern;
while (toupper(*sptr) == toupper(*pptr)) {
sptr++;
pptr++;
if ('\0' == *pptr)
return (start);
}
}
return (NULL);
}
char *trimstr1(char *s)
{
int i;
static char *whitespace = " \r\n\t";
i = strlen(s);
while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
--i;
while ((i > 0) && (_fstrchr(whitespace, *s))) {
memmove(s, s + 1, --i);
}
s[i] = 0;
return (s);
}
int log_it(int display, char *fmt,...)
{
va_list v;
char s[255], fn[MAXPATH];
FILE *fp;
sprintf(fn, "%sNEWS.LOG", net_data);
if ((fp = fsh_open(fn, "at")) == NULL)
return 1;
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, fp);
fclose(fp);
if (display)
fputs(s, stderr);
return 0;
}
int count_lines(char *s)
{
FILE *fp;
char fn[201];
unsigned int nl = 0;
const int NEWLINE = '\n';
int c;
strcpy(fn, s);
if ((fp = fsh_open(fn, "rt")) == NULL) {
output("\n ■ Cannot open %s", fn);
return 0;
}
while ((c = getc(fp)) != EOF) {
if (c == NEWLINE)
++nl;
}
fclose(fp);
return nl;
}
int exist(char *s)
{
int i;
struct ffblk ff;
i = findfirst(s, &ff, 0);
if (i)
return (0);
else
return (1);
}
void rename_pend(char *file)
{
char s[181], s1[181];
int i, ok;
sprintf(s, "%s%s", net_data, file);
ok = 0;
for (i = 0; i < 1000 && !ok; i++) {
sprintf(s1, "%sP0-%u.NET", net_data, i);
if (!exist(s1)) {
rename(s, s1);
ok = 1;
}
}
}
void check_packets(void)
{
char s[MAXPATH], s1[MAXPATH];
int f1;
struct ffblk ff;
sprintf(s, "%sP0-*.%3.3d", net_data, instance);
f1 = findfirst(s, &ff, 0);
while (f1 == 0) {
if (ff.ff_fsize == 0L) {
sprintf(s1, "%s%s", net_data, ff.ff_name);
if (unlink(s1) != 0)
rename_pend(ff.ff_name);
} else
rename_pend(ff.ff_name);
f1 = findnext(&ff);
}
}
void write_groups(int display)
{
int i;
char fn[160];
FILE *groupfp;
sprintf(fn, "%sNEWS.RC", net_data);
if ((groupfp = fsh_open(fn, "wt+")) == NULL) {
output("\n ■ Unable to open %s!", fn);
return;
} else {
if ((display) && (MOREINFO))
output("\n ■ Updating message pointers..");
}
for (i = 0; i < ngroups; i++)
if ((*grouprec[i].groupname) && (stricmp(grouprec[i].groupname, "newsrc") != 0))
fprintf(groupfp, "%s %lu %s\n", grouprec[i].groupname,
grouprec[i].lastread, grouprec[i].subtype);
if (groupfp != NULL)
fclose(groupfp);
}
void nntp_shutdown(Mail_Socket * NNTP_sock)
{
if (NNTP_sock->sock != NULL) {
sock_puts(NNTP_sock->sock, "QUIT");
sock_close(NNTP_sock->sock);
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
}
sock_err:
return;
}
void read_groups(void)
{
int i = 0, ok;
unsigned short sn;
char *ss, fn[101], fn1[160], tmp[121];
FILE *groupfp;
sprintf(fn1, "%sNEWS.RC", net_data);
ngroups = count_lines(fn1);
if (!ngroups)
return;
if (grouprec != NULL)
farfree(grouprec);
grouprec = NULL;
grouprec = (GROUPFILEREC *) farmalloc((ngroups + 1) * sizeof(GROUPFILEREC));
if (!grouprec) {
ngroups = 0;
output("\n ■ Insufficient memory for %d groups in %s.", ngroups, fn1);
return;
}
if ((groupfp = fsh_open(fn1, "rt")) == NULL) {
if (grouprec != NULL)
farfree(grouprec);
ngroups = 0;
return;
}
while (fgets(tmp, 120, groupfp)) {
if (*tmp) {
if (strncmpi(tmp, "newsrc", 6) == 0) {
strcpy(grouprec[i].groupname, "newsrc");
++i;
} else {
ss = strtok(tmp, " ");
strcpy(grouprec[i].groupname, ss);
ss = strtok(NULL, " ");
if (ss) {
grouprec[i].lastread = atol(ss);
ss = strtok(NULL, " \n");
if (ss) {
strcpy(grouprec[i].subtype, strupr(ss));
++i;
}
}
}
}
}
ngroups = i;
if (groupfp != NULL)
fclose(groupfp);
for (i = 0; i < ngroups; i++) {
if ((grouprec[i].subtype) && (atoi(grouprec[i].subtype) != 0)) {
sprintf(fn, "%sN%s.NET", net_data, grouprec[i].subtype);
if (exist(fn)) {
ok = 0;
if ((groupfp = fsh_open(fn, "rt")) != NULL) {
while ((fgets(tmp, 25, groupfp)) && !ok) {
sn = atoi(tmp);
if (sn == 32767)
ok = 1;
}
fclose(groupfp);
}
if (!ok)
log_it(1, "\n ■ @32767 not listed as a subscriber in N%s.NET!",
grouprec[i].subtype);
}
}
}
}
int sendauthinfo(Mail_Socket * NNTP_sock)
{
char s[MAXPATH], buf[STR];
*_temp_buffer = 0;
log_it(MOREINFO, "\n ■ Server requested authentication information.");
while (1) {
sprintf(buf, "authinfo user %s", NEWSNAME);
sock_printf(NNTP_sock->sock, buf);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %s", &reply, s);
if (reply == 381) {
sprintf(buf, "authinfo pass %s", NEWSPASS);
sock_printf(NNTP_sock->sock, buf);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %s", &reply, s);
if (reply == 281) {
output("\n ■ Authentication accepted. Continuing news retrieval session.");
return 1;
} else {
output("\n ■ Authentication failed. Aborting news session.");
return 0;
}
} else {
output("\n ■ Unknown AUTHINFO response %s.", _temp_buffer);
return 0;
}
}
SOCK_READ_ERR(NNTP);
return 0;
}
int cgroup(Mail_Socket * NNTP_sock, char *s)
{
char junk[STRING];
*_temp_buffer = 0;
sock_printf(NNTP_sock->sock, "GROUP %s", s);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
switch (reply) {
case 411:
return 0;
case 211:
sscanf(_temp_buffer, "%hu %lu %lu %lu %s",
&reply, &cur_numa, &cur_first, &cur_last, junk);
return 1;
case 480:
return (-1);
default:
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
log_it(MOREINFO, "\n ■ Unknown GROUP response : %s", _temp_buffer);
break;
}
SOCK_READ_ERR(NNTP);
return 0;
}
char *treat(char *string)
{
char *s;
if (!string || !*string)
return NULL;
for (s = string; *s; ++s) {
if ((*s < 32) || (*s > 126)) {
if ((*s != 9) && (*s != 10)) {
memmove(s, s + 1, strlen(s) + 1);
--s;
}
}
}
return string;
}
char *name_packet(char *pktname)
{
int i;
for (i = 0; i < 1000; i++) {
sprintf(pktname, "%sP0-%5.5d.%3.3d", net_data, i, instance);
if (!exist(pktname))
break;
}
return pktname;
}
int jgets(char *s, int maxlen)
{
char temp[500];
int done = 0, pos = 0, length = 0, i, c, zeroflag;
while (!done) {
zeroflag = 0;
if ((c = getch()) == 0) {
zeroflag = 1;
c = getch();
}
switch (c) {
case 27:
return 0;
case 8:
if (c == 8) {
if (pos == 0)
break;
if (pos != length) {
for (i = pos - 1; i < length; i++)
temp[i] = temp[i + 1];
pos--;
length--;
putch(8);
for (i = pos; i < length; i++)
putch(temp[i]);
for (i = length; i >= pos; i--)
putch(8);
} else {
putch(8);
pos = --length;
}
break;
}
case 13:
if (c == 13) {
done = 1;
break;
}
default:
if (zeroflag)
break;
if (c == 0 || pos == maxlen)
break;
if (pos == length) {
temp[pos++] = c;
if (pos > length)
length++;
putch(c);
} else {
for (i = length++; i >= pos; i--)
temp[i + 1] = temp[i];
temp[pos++] = c;
putch(c);
for (i = pos; i < length; i++)
putch(temp[i]);
for (i = length; i > pos; i--)
putch(8);
}
}
}
temp[length] = '\0';
strcpy(s, temp);
return length;
}
int savebody(Mail_Socket * NNTP_sock, char *fn, int cug, unsigned long cur_article, int *abort)
{
int i, f, place, length, curpos, count, part;
char _big_temp_buffer[BIGSTR];
char ch, spin[15], buf[STRING];
unsigned long msgsize;
place = count = 0;
*_temp_buffer = 0;
part = 1;
strcpy(spin, "||//--\\\\");
length = strlen(spin);
if (spooltodisk)
f = sh_open(fn, O_RDWR | O_APPEND | O_TEXT | O_CREAT, S_IREAD | S_IWRITE);
else
f = sh_open(fn, O_RDWR | O_TEXT | O_CREAT | O_TRUNC, S_IWRITE);
if (f < 0) {
log_it(MOREINFO, "\n ■ Unable to write to %s.", fn);
return 0;
}
sock_printf(NNTP_sock->sock, "BODY %ld", cur_article);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
sscanf(_big_temp_buffer, "%hu %lu", &reply, &reparticle);
switch (reply) {
case 423:
return 0;
case 222:
sh_write(f, "\n", sizeof(char));
if (spooltodisk) {
if (MOREINFO)
output("\n ■ NEWS%d.UUE - [Esc], [Space], [Tab], ] = +10, } = +100, + = User Input [-]", cug);
for (i = 0; i < 79; i++)
sh_write(f, "-", sizeof(char));
sh_write(f, "\n", sizeof(char));
sprintf(buf, "Art : %lu\n", cur_article);
sh_write(f, buf, strlen(buf));
if (*cur_lines) {
if ((atol(cur_lines) > 0L) && (atol(cur_lines) < 99999L))
sprintf(buf, "Lines: %s\n", cur_lines);
else
sprintf(buf, "Lines: Unknown\n");
}
sh_write(f, buf, strlen(buf));
sprintf(buf, "Group: %s\n", grouprec[cug].groupname);
sh_write(f, buf, strlen(buf));
if (*cur_date)
sprintf(buf, "Date : %s\n", cur_date);
else
sprintf(buf, "Date : Unknown\n");
sh_write(f, buf, strlen(buf));
if (*cur_replyto)
sprintf(buf, "From : %s\n", cur_replyto);
else
sprintf(buf, "From : Unknown\n");
sh_write(f, buf, strlen(buf));
if (*cur_subject)
sprintf(buf, "Subj : %s\n\n", cur_subject);
else
sprintf(buf, "Subj : Unknown\n");
sh_write(f, buf, strlen(buf));
} else {
if (*cur_replyto) {
sprintf(buf, "0RReply-To: %s\n", cur_replyto);
sh_write(f, buf, strlen(buf));
}
if (*cur_message_ID) {
sprintf(buf, "0RMessage-ID: %s\n", cur_message_ID);
sh_write(f, buf, strlen(buf));
}
if (*cur_references) {
sprintf(buf, "0RReferences: %s\n", cur_references);
sh_write(f, buf, strlen(buf));
}
if (MOREINFO)
output("\n ■ Receiving message - [Esc] Abort - [Space] Skip Group - [Tab] Catch Up [-]");
else
output(" [-]");
}
msgsize = 0L;
curpos = 0L;
while (1) {
while (kbhit()) {
ch = (getch());
strcpy(spin, "..oOOOo.");
length = strlen(spin);
switch (ch) {
case '+':
if (spooltodisk) {
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Jumping forward... wait until message is completed [.]");
}
*abort = 6;
}
break;
case '}':
if (spooltodisk) {
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Jumping 100 articles... wait until message is completed [.]");
}
*abort = 5;
}
break;
case ']':
if (spooltodisk) {
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Jumping 10 articles... wait until message is completed [.]");
}
*abort = 4;
}
break;
case 9:
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Catching up on group... wait until message is completed [.]");
}
*abort = 3;
break;
case 32:
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Skipping group... wait until message is completed [.]");
}
*abort = 2;
break;
case 27:
if (MOREINFO) {
backline();
log_it(MOREINFO, "\r ■ Aborting session... wait until message is completed [.]");
}
*abort = 1;
break;
default:
break;
}
}
if (count++ > 5) {
output("\b\b%c]", spin[place++]);
if (length)
place %= length;
count = 0;
}
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
if (_big_temp_buffer[0] == '.' && _big_temp_buffer[1] == 0)
break;
else {
treat(_big_temp_buffer);
if (*_big_temp_buffer) {
strcat(_big_temp_buffer, "\n");
curpos = strlen(_big_temp_buffer);
sh_write(f, _big_temp_buffer, strlen(_big_temp_buffer));
msgsize += curpos;
}
}
if ((msgsize > 30000L) && (!spooltodisk)) {
strcpy(buf, "\nContinued in next message...\n");
sh_write(f, buf, strlen(buf));
sh_close(f);
sprintf(fn, "%sSPOOL\\INPUT%d.MSG", net_data, ++part);
unlink(fn);
if ((f = sh_open(fn, O_WRONLY | O_TEXT | O_CREAT | O_TRUNC, S_IWRITE)) < 0) {
log_it(MOREINFO, "\n ■ Unable to create %s", fn);
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
return 0;
}
if (MOREINFO) {
backline();
output("\r ■ Breaking into %d%s part [ ]", (part), ordinal_text(part));
}
strcpy(buf, "\nContinued from previous message...\n");
sh_write(f, buf, strlen(buf));
msgsize = strlen(buf);
}
}
sh_close(f);
output("\b\bX]");
return 1;
default:
log_it(MOREINFO, "\n ■ Unknown BODY error : %s", _temp_buffer);
break;
}
sh_close(f);
SOCK_READ_ERR(NNTP);
return 0;
}
int extract(char *to, char *key, char *from)
{
if (!strnicmp(from, key, strlen(key))) {
from += strlen(key);
while (*from == ' ')
from++;
strcpy(to, from);
return 1;
} else
return 0;
}
int chead(Mail_Socket * NNTP_sock, unsigned long which)
{
char _big_temp_buffer[BIGSTR];
*cur_path = 0;
*cur_from = 0;
*cur_replyto = 0;
*cur_subject = 0;
*cur_newsgroups = 0;
*cur_message_ID = 0;
*cur_references = 0;
*cur_date = 0;
*_temp_buffer = 0;
sock_printf(NNTP_sock->sock, "HEAD %lu", which);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
sscanf(_big_temp_buffer, "%hu %lu", &reply, &reparticle);
switch (reply) {
case 423:
output("%-55.55s", "Expired article.");
return 0;
case 221:
while (1) {
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
if (_big_temp_buffer[0] == '.' && _big_temp_buffer[1] == 0) {
if (cur_replyto[0] == 0)
strcpy(cur_replyto, cur_from);
if (cur_subject[0] == 0)
strcpy(cur_subject, "No Subject");
return 1;
}
if ((strlen(_big_temp_buffer)) > STRING)
_big_temp_buffer[STRING] = '\0';
if (extract(cur_path, "Path:", _big_temp_buffer) ||
extract(cur_from, "From:", _big_temp_buffer) ||
extract(cur_subject, "Subject:", _big_temp_buffer) ||
extract(cur_replyto, "Reply-To:", _big_temp_buffer) ||
extract(cur_newsgroups, "Newsgroups:", _big_temp_buffer) ||
extract(cur_organization, "Organization:", _big_temp_buffer) ||
extract(cur_message_ID, "Message-ID:", _big_temp_buffer) ||
extract(cur_references, "References:", _big_temp_buffer) ||
extract(cur_lines, "Lines:", _big_temp_buffer) ||
extract(cur_date, "Date:", _big_temp_buffer))
continue;
}
default:
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
log_it(MOREINFO, "\n ■ Unknown chead error : %s", _big_temp_buffer);
break;
}
SOCK_READ_ERR(NNTP);
return 0;
}
Mail_Socket *netsocket(char *host)
{
Mail_Socket *NNTP_sock = NULL;
longword h;
sock_init();
if (!(h = resolve(host))) {
if (!(h = resolve(host))) {
log_it(1, "\n ■ Error : Cannot resolve host %s", host);
return NULL;
}
}
if ((NNTP_sock = (Mail_Socket *) farmalloc(sizeof(Mail_Socket))) == NULL) {
log_it(1, "\n ■ Error: Insufficient memory to create socket... aborting.");
return NULL;
}
if ((NNTP_sock->sock = (tcp_Socket *) farmalloc(sizeof(tcp_Socket))) == NULL) {
log_it(1, "\n ■ Error : Insufficient memory to create socket... aborting.");
farfree(NNTP_sock);
return NULL;
}
if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
log_it(1, "\n ■ Error : Unable to connect to to %s.", host);
farfree(NNTP_sock);
return NULL;
}
sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
sock_wait_established(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
switch (reply) {
case 200:
log_it(MOREINFO, "\n ■ Connection to %s accepted...", host);
return (NNTP_sock);
case 502:
log_it(1, "\n ■ Connection to %s refused... try again later.", host);
break;
case 503:
log_it(1, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
break;
default:
log_it(1, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
break;
}
SOCK_READ_ERR(NNTP);
return 0;
}
int cnext(Mail_Socket * NNTP_sock)
{
char *p, *q;
*_temp_buffer = 0;
sock_printf(NNTP_sock->sock, "NEXT");
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
switch (reply) {
case 421:
return 0;
case 223:
p = _temp_buffer;
q = cur_articleid;
while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
p++;
while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
*q++ = *p++;
*q++ = '>';
*q++ = '\0';
return 1;
default:
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
log_it(MOREINFO, "\n ■ Unknown NEXT error : %s", _temp_buffer);
break;
}
SOCK_READ_ERR(NNTP);
return 0;
}
int cslave(Mail_Socket * NNTP_sock)
{
char junk[STRING];
*_temp_buffer = 0;
sock_printf(NNTP_sock->sock, "SLAVE");
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %s", &reply, junk);
SOCK_READ_ERR(NNTP);
return 0;
}
char *stripspace(char *str)
{
char *obuf, *nbuf;
if (str) {
for (obuf = str, nbuf = str; *obuf; ++obuf) {
if (!isspace(*obuf))
*nbuf++ = *obuf;
}
*nbuf = NULL;
}
return (str);
}
int saveactive(Mail_Socket * NNTP_sock, int forced)
{
char s[181], fn[MAXPATH], group[256], act;
unsigned long to, from;
unsigned fnday, fnmonth, fnyear, fnhour, fnminute, fnsecond;
int f, done, update;
unsigned long count;
FILE *fp;
struct ftime ft;
struct date d;
*_temp_buffer = 0;
update = 0;
sprintf(fn, "%sNEWSRC", net_data);
f = sh_open1(fn, O_RDONLY);
if (f < 0)
forced = 1;
else {
getftime(f, &ft);
sh_close(f);
}
getdate(&d);
if ((ft.ft_month == 12) && ((d.da_day == 1) && (d.da_mon == 1))) {
unlink(fn);
forced = 1;
}
if (!forced) {
fnsecond = 2 * ft.ft_tsec;
fnminute = ft.ft_min;
fnhour = ft.ft_hour;
fnday = ft.ft_day;
fnmonth = ft.ft_month;
fnyear = ft.ft_year + 80;
log_it(1, "\n ■ NEWSRC last updated %02u/%02u/%02u %.2u:%.2u:%.2u... ",
fnmonth, fnday, fnyear, fnhour, fnminute, fnsecond);
if ((d.da_day == ft.ft_day) && (d.da_mon == ft.ft_month) &&
(d.da_year == (ft.ft_year + 1980))) {
log_it(1, "no update required.");
return 0;
} else
log_it(1, "updating.");
if ((d.da_mon == ft.ft_month) && (d.da_day != ft.ft_day))
update = 1;
}
if (update)
fp = fsh_open(fn, "a+");
else
fp = fsh_open(fn, "w+");
if (fp == NULL) {
perror(fn);
return 0;
}
done = 0;
while (!done) {
if (update) {
sprintf(s, "NEWGROUPS %02.02u%02.02u%02.02u %02.02u%02.02u%02.02u",
fnyear, fnmonth, fnday, fnhour, fnminute, fnsecond);
sock_printf(NNTP_sock->sock, s);
output("\n ■ Refreshing NEWSRC newsgroup listing : ");
} else {
sock_printf(NNTP_sock->sock, "LIST");
output("\n ■ Retrieving current newsgroup listing : ");
}
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
if ((reply == 215) || (reply == 231)) {
count = 0L;
while (1) {
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
if (*_temp_buffer == '.' && _temp_buffer[1] == 0)
break;
if (strlen(_temp_buffer) < 180) {
if (count++ % 25 == 24L)
output("\b\b\b\b\b\b\b%-7lu", count);
sscanf(_temp_buffer, "%s %lu %lu %c", group, &to, &from, &act);
sprintf(s, "%s %lu\n", group, to);
fsh_write(s, sizeof(char), strlen(s), fp);
}
}
if (update) {
if (count == 0) {
log_it(1, "\b\b\b\b\b\b\bNo new groups.");
} else
log_it(1, "\b\b\b\b\b\b\b%lu group%s added to NEWSRC.", count,
count == 1 ? "" : "s");
} else
output("\b\b\b\b\b\b\b%lu total groups.", count);
if (fp != NULL)
fclose(fp);
if (update) {
f = sh_open1(fn, O_RDWR);
ft.ft_day = d.da_day;
setftime(f, &ft);
sh_close(f);
}
return 1;
} else {
if (reply == 480) {
if (fp != NULL)
fclose(fp);
return 0;
} else {
log_it(MOREINFO, "\n ■ Unknown saveactive error : %s", _temp_buffer);
if (fp != NULL)
fclose(fp);
done = 1;
}
}
}
if (fp != NULL)
fclose(fp);
SOCK_READ_ERR(NNTP);
return 0;
}
int checkx(int cug)
{
char *ptr, *ptr2, *ptr3, fn[MAXPATH], buf[256], tmp[81];
int i, spam, max, ok;
FILE *fp;
if ((stristr(grouprec[cug].groupname, "binaries")) && (binxpost))
return 1;
sprintf(buf, "%s!%s", POPNAME, POPDOMAIN);
if (stristr(cur_path, buf) != 0) {
sprintf(buf, "Local post - %s - skipped.", cur_subject);
output("%-55.55s", buf);
return 0;
}
ok = 1;
spam = 0;
sprintf(fn, "%sNOSPAM.TXT", net_data);
if ((fp = fsh_open(fn, "r")) != NULL) {
while ((!feof(fp)) && (!spam)) {
fgets(buf, 80, fp);
trimstr1(buf);
if (strlen(buf) > 2) {
if (buf[0] == '\"') {
strcpy(tmp, &(buf[1]));
LAST(tmp) = '\0';
strcpy(buf, tmp);
}
if (buf[0] == '[') {
if ((strnicmp(buf, "[GLOBAL]", 8) == 0) || (strnicmp(buf, "[NEWS]", 6) == 0))
ok = 1;
else
ok = 0;
}
if ((ok) && ((stristr(cur_subject, buf)) || (stristr(cur_from, buf)))) {
sprintf(tmp, "SPAM - %s - skipped.", buf);
output("%-55.55s", tmp);
spam = 1;
}
}
}
fclose(fp);
if (spam)
return 0;
}
ptr = cur_newsgroups;
while (*ptr == ' ')
ptr++;
max = 0;
while (1) {
if (*ptr == 0)
break;
if (*ptr == ',') {
ptr++;
++max;
}
while (*ptr == ' ')
ptr++;
ptr2 = ptr;
ptr3 = buf;
while (*ptr2 != 0 && *ptr2 != ',')
*ptr3++ = *ptr2++;
*ptr3 = 0;
while (*(--ptr3) == ' ')
*ptr3 = 0;
ptr = ptr2;
for (i = 0; i < cug; i++) {
if (strcmpi(buf, grouprec[i].groupname) == 0) {
output("Already posted in %s.", grouprec[i].groupname);
return 0;
}
}
if ((crossposts > 0) && (max > crossposts)) {
sprintf(buf, "Crossposted to more than %d newsgroups.", crossposts);
output("%-55.55s", buf);
return 0;
}
}
return 1;
}
char *strrep(char *str, char old, char New)
{
int i;
for (i = 0; str[i]; i++)
if (str[i] == old)
str[i] = New;
return (str);
}
int postnews(Mail_Socket * NNTP_sock, int cug)
{
char s[160], s1[12], s2[5], fn[MAXPATH], *ss;
int f1, nlines;
FILE *fp;
struct ffblk ff;
*_temp_buffer = 0;
sprintf(fn, "%sOUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
f1 = findfirst(fn, &ff, 0);
if (f1 != 0) {
log_it(MOREINFO, "\n ■ No outbound news articles to post...");
return 1;
}
while (f1 == 0) {
sock_printf(NNTP_sock->sock, "POST");
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
if (*_temp_buffer != '3') {
if (atoi(_temp_buffer) == 440)
log_it(MOREINFO, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
else
log_it(1, "\n ■ Remote error: %s", _temp_buffer);
return 0;
}
if (MOREINFO)
output("\n");
else
backline();
output(" ■ Posting article to %s\n", grouprec[cug].groupname);
sprintf(s, "%sOUTBOUND\\%s", net_data, ff.ff_name);
if ((fp = fsh_open(s, "r")) == NULL) {
log_it(MOREINFO, "\n ■ Error reading %s.", s);
return 1;
}
nlines = 0;
while (!feof(fp)) {
fgets(_temp_buffer, sizeof(_temp_buffer), fp);
strrep(_temp_buffer, '\n', '\0');
strrep(_temp_buffer, '\r', '\0');
if (*_temp_buffer == '.') {
movmem(_temp_buffer, _temp_buffer + 1, sizeof(_temp_buffer) - 1);
*_temp_buffer = '.';
}
sock_puts(NNTP_sock->sock, _temp_buffer);
if (MOREINFO) {
backline();
output("\r ■ Lines sent : %d", ++nlines);
}
}
fclose(fp);
sock_puts(NNTP_sock->sock, ".");
if (MOREINFO)
output("\n ■ Awaiting acknowledgement - may take several minutes...");
log_it(MOREINFO, "\n ■ Server response : ");
sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
log_it(MOREINFO, "%s", _temp_buffer);
if (*_temp_buffer != '2') {
sscanf(_temp_buffer, "%hu %s", &reply, s);
if (reply == 441) {
ss = strtok(_temp_buffer, " ");
ss = strtok(NULL, " ");
if (atoi(ss) == 435)
unlink(s);
fnsplit(s, NULL, NULL, s1, s2);
log_it(MOREINFO, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
if (unlink(s) == 0)
log_it(MOREINFO, "\n ■ Deleted message - %s", s);
} else
log_it(MOREINFO, "\n ■ Remote error: %s", _temp_buffer);
} else {
if (unlink(s) == 0)
log_it(MOREINFO, "\n ■ Deleted sent message - %s", s);
}
f1 = findnext(&ff);
}
SOCK_READ_ERR(NNTP);
return 0;
}
void get_subtype(int sub, char *where)
{
int ok, which;
char fn[181], s[81], net_name[21], *ss;
FILE *fp;
where[0] = 0;
which = sub;
sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
if ((fp = fsh_open(fn, "r")) == NULL)
return;
ok = 0;
while (fgets(s, 80, fp)) {
if (*s == '!') {
if (which == atoi(&s[1]))
ok = 1;
}
if (ok && (*s == '$')) {
ss = strtok(s, " ");
strcpy(net_name, &ss[1]);
ss = strtok(NULL, " ");
if (fp != NULL)
fclose(fp);
if ((stricmp(net_name, "FILENET") == 0)) {
trimstr1(ss);
strcpy(where, ss);
return;
} else
return;
}
}
if (fp != NULL)
fclose(fp);
}
unsigned long max_on_sub(int cug)
{
int i, num_subs;
char fn[MAXPATH], subtype[12];
unsigned long max;
subboardrec sub;
FILE *fp;
max = 0;
if ((strlen(grouprec[cug].subtype) == 1) && (*grouprec[cug].subtype == '0'))
return max;
if (MOREINFO)
output("\n ■ Max articles - ");
else
output(" - ");
sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
if ((fp = fsh_open(fn, "rb")) == NULL) {
log_it(MOREINFO, "\n ■ Unable to read %s.", fn);
return max;
} else {
fseek(fp, 0L, SEEK_END);
num_subs = (int) (ftell(fp) / sizeof(subboardrec));
for (i = 0; i < num_subs; i++) {
output("\b\b\b\b%-4d", i);
fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
fread(&sub, sizeof(subboardrec), 1, fp);
get_subtype(i, subtype);
if (stricmp(subtype, grouprec[cug].subtype) == 0) {
max = (unsigned long)sub.maxmsgs;
if (MOREINFO)
output("\b\b\b\b%s (%s) - %lu posts.", sub.name, subtype, max);
else
output("\b\b\b\b [%lu max]", max);
break;
}
}
}
fclose(fp);
return max;
}
int getnews(Mail_Socket * NNTP_sock)
{
int f1, nup, nug, cug, jug, abort, ok, done, firstrun, parts, skipped, bogus;
char *p, fn[MAXPATH], mailname[121], reline[121], pktname[MAXPATH];
char ch, orig_subj[STRING], buf[STR];
unsigned int text_len;
unsigned short temptype;
unsigned long new_articles, max_articles, skip_articles;
net_header_rec nh;
struct ffblk ff;
FILE *fp;
abort = cug = bogus = 0;
if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
if (!saveactive(NNTP_sock, 1)) {
if (sendauthinfo(NNTP_sock))
saveactive(NNTP_sock, 1);
}
} else {
if (newsrc_upd)
saveactive(NNTP_sock, 0);
}
nug = jug = nup = 1;
skipped = 0;
cslave(NNTP_sock);
name_packet(pktname);
if (!MOREINFO)
output("\n ■ [Esc] aborts session - [Space] skips group - [Tab] catches up group");
while ((cug < ngroups) && (!abort)) {
if (*grouprec[cug].groupname == ';') {
log_it(1, "\n ■ Skipping commented group - %s", &(grouprec[cug].groupname[1]));
++cug;
jug = 1;
continue;
}
if (*grouprec[cug].subtype == '0')
spooltodisk = 1;
else
spooltodisk = 0;
if (nup) {
nup = 0;
write_groups(1);
if (*grouprec[cug].subtype != '0')
name_packet(pktname);
}
if (nug) {
jug = 1;
nug = 0;
while (1) {
if (!cgroup(NNTP_sock, grouprec[cug].groupname)) {
if (cgroup(NNTP_sock, grouprec[cug].groupname) == -1) {
if (sendauthinfo(NNTP_sock))
continue;
else
return 1;
}
if (++bogus > 10) {
log_it(1, "\n ■ Too many invalid newsgroups... NEWS.RC error?");
return 1;
}
log_it(1, "\n ■ Error accessing - %s", grouprec[cug].groupname);
nug = 1;
break;
} else
break;
}
if (!nug) {
log_it(1, "\n ■ Requesting - %s - ", grouprec[cug].groupname);
if (grouprec[cug].lastread < cur_first)
grouprec[cug].lastread = cur_first;
if (grouprec[cug].lastread >= cur_last) {
grouprec[cug].lastread = cur_last;
log_it(1, "[No new articles]");
nug = jug = 1;
} else {
new_articles = cur_last - grouprec[cug].lastread;
if (new_articles) {
log_it(1, "[%lu new article%s]", new_articles,
new_articles == 1 ? "" : "s");
} else {
log_it(1, "[No new articles]");
nug = jug = 1;
}
if (new_articles > 250L) {
max_articles = max_on_sub(cug);
if (max_articles && (new_articles > max_articles)) {
log_it(MOREINFO, "\n ■ Requesting most recent %lu articles", max_articles);
grouprec[cug].lastread = cur_last - max_articles;
}
} else
++grouprec[cug].lastread;
}
postnews(NNTP_sock, cug);
if (!nug) {
if (cur_numa == 0) {
log_it(MOREINFO, "\n ■ No articles in %s...", grouprec[cug].groupname);
nug = jug = 1;
continue;
}
}
}
} else {
if ((!cnext(NNTP_sock)) || (grouprec[cug].lastread > cur_last)) {
log_it(MOREINFO, "\n ■ End of articles in %s", grouprec[cug].groupname);
nug = jug = 1;
write_groups(0);
}
}
if (!nug) {
if (skipped)
backline();
else
output("\n");
output(" ■ [%lu/%lu] : ", grouprec[cug].lastread, cur_last);
if ((chead(NNTP_sock, grouprec[cug].lastread)) && (checkx(cug))) {
skipped = 0;
if (*cur_subject) {
if (strlen(cur_subject) > 78)
cur_subject[78] = 0;
treat(cur_subject);
}
strcpy(orig_subj, cur_subject);
if (strlen(orig_subj) > 70)
orig_subj[70] = 0;
if (*cur_from) {
treat(cur_from);
if (strlen(cur_from) > 45)
cur_from[45] = 0;
} else
strcpy(cur_from, "Unknown");
if (*cur_replyto) {
if (strlen(cur_replyto) > 45)
cur_replyto[45] = 0;
} else
strcpy(cur_replyto, "Unknown");
output("%-50.50s", orig_subj);
if (spooltodisk)
sprintf(fn, "%sSPOOL\\NEWS%d.UUE", net_data, cug);
else
sprintf(fn, "%sSPOOL\\INPUT1.MSG", net_data);
abort = 0;
fcloseall();
ok = (savebody(NNTP_sock, fn, cug, grouprec[cug].lastread, &abort));
if (ok && (*grouprec[cug].subtype != '0')) {
if ((fp = fsh_open(pktname, "ab+")) == NULL) {
log_it(MOREINFO, "\n ■ Unable to create %s!", pktname);
return 1;
}
sprintf(fn, "%sSPOOL\\INPUT*.MSG", net_data);
done = 1;
parts = 0;
if (findfirst(fn, &ff, 0) == 0) {
parts = 1;
done = 0;
}
firstrun = 1;
while (!done) {
sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
f1 = sh_open1(fn, O_RDONLY | O_BINARY);
text_len = (unsigned int) filelength(f1);
if (text_len > 32000L) {
log_it(MOREINFO, "\n ■ Truncating %lu bytes from input file",
text_len - 32000L);
text_len = 32000;
}
if ((p = (char *) malloc(32767)) == NULL) {
log_it(MOREINFO, "\n ■ Insufficient memory to read entire message");
return 1;
}
sh_read(f1, (void *) p, text_len);
sh_close(f1);
temptype = atoi(grouprec[cug].subtype);
nh.tosys = sy;
nh.touser = 0;
nh.fromsys = 32767;
nh.fromuser = 0;
if (!temptype) {
nh.main_type = main_type_new_post;
nh.minor_type = 0;
} else {
nh.main_type = main_type_pre_post;
nh.minor_type = temptype;
}
nh.list_len = 0;
++cur_daten;
nh.daten = cur_daten;
nh.method = 0;
if (parts > 1) {
sprintf(buf, "%d%s ", parts, ordinal_text(parts));
strncat(buf, orig_subj, 72);
strcpy(cur_subject, buf);
cur_subject[72] = '\0';
}
nh.length = text_len + strlen(cur_subject) + 1;
strncpy(mailname, cur_replyto, 46);
strcat(mailname, "\r\n");
nh.length += strlen(mailname);
if (nh.main_type == main_type_new_post)
nh.length += strlen(grouprec[cug].subtype) + 1;
if (firstrun) {
firstrun = 0;
if (strncmpi(cur_articleid, "re: ", 4) == 0) {
strncpy(reline, cur_articleid, 60);
sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
}
}
if (!*cur_date) {
strncpy(cur_date, ctime(&(time_t) nh.daten), 24);
cur_date[24] = '\0';
}
strcat(cur_date, "\r\n");
nh.length += strlen(cur_date);
nh.length += strlen(cur_articleid);
fsh_write(&nh, sizeof(net_header_rec), 1, fp);
if (nh.main_type == main_type_new_post)
fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
fsh_write(mailname, sizeof(char), strlen(mailname), fp);
fsh_write(cur_date, sizeof(char), strlen(cur_date), fp);
fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
fsh_write(p, sizeof(char), text_len, fp);
if (p)
free(p);
unlink(fn);
if (findnext(&ff) == 0) {
done = 0;
++parts;
} else
done = 1;
}
if (filelength(fileno(fp)) > 250000L)
nup = 1;
if (fp != NULL)
fclose(fp);
}
} else
skipped = 1;
++grouprec[cug].lastread;
while (kbhit()) {
ch = (getch());
switch (ch) {
case '+':
if (spooltodisk) {
if (MOREINFO)
backline();
abort = 6;
}
break;
case '}':
if (spooltodisk) {
if (MOREINFO)
backline();
abort = 5;
}
break;
case ']':
if (spooltodisk) {
if (MOREINFO)
backline();
abort = 4;
}
break;
case 9:
abort = 3;
break;
case 32:
abort = 2;
break;
case 27:
abort = 1;
break;
default:
break;
}
}
switch (abort) {
case 6:
backline();
output(" ? Skip how many articles? ");
if (jgets(buf, 10)) {
skip_articles = atol(buf);
if ((grouprec[cug].lastread += skip_articles) < cur_last) {
abort = 0;
break;
}
} else
break;
case 5:
if ((grouprec[cug].lastread += 100) < cur_last) {
abort = 0;
break;
}
case 4:
if ((grouprec[cug].lastread += 10) < cur_last) {
abort = 0;
break;
}
case 3:
grouprec[cug].lastread = cur_last;
case 2:
nug = jug = 1;
abort = 0;
break;
default:
break;
}
}
if (nug) {
++cug;
if (*grouprec[cug].subtype == '0')
nup = 1;
}
}
write_groups(1);
nntp_shutdown(NNTP_sock);
if (abort)
log_it(1, "\n ■ Session aborted from keyboard");
return 0;
}
int copyfile(char *input, char *output)
{
int f1, f2, i;
char *b;
struct ftime ft;
if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
if ((b = (char *) malloc(16400)) == NULL)
return 0;
f1 = sh_open1(input, O_RDONLY | O_BINARY);
if (!f1) {
free(b);
b = NULL;
return 0;
}
getftime(f1, &ft);
f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (!f2) {
free(b);
b = NULL;
f1 = sh_close(f1);
return 0;
}
i = read(f1, (void *) b, 16384);
while (i > 0) {
sh_write(f2, (void *) b, i);
i = read(f1, (void *) b, 16384);
}
f1 = sh_close(f1);
setftime(f2, &ft);
f2 = sh_close(f2);
free(b);
b = NULL;
}
return 1;
}
main(int argc, char *argv[])
{
int ok, f, bAuth;
char s[160], fn[MAXPATH], tempfn[MAXPATH], serverhost[50], *ss;
FILE *fp;
struct date dt;
struct time tm;
Mail_Socket *nntp_sock = NULL;
crossposts = 10;
binxpost = 0;
newsrc_upd = 0;
MOREINFO = 1;
POPNAME[0] = 0;
POPDOMAIN[0] = 0;
cursor('S');
cursor('H');
output("\n ■ %s", version);
if (argc != 4) {
output("\n ■ Invalid arguments for %s\n", argv[0]);
cursor('R');
return EXIT_FAILURE;
}
strcpy(net_data, argv[1]);
strcat(net_data, "\\");
strcpy(serverhost, argv[2]);
sy = atoi(argv[3]);
get_dir(maindir, 0);
detect_multitask();
gettime(&tm);
getdate(&dt);
cur_daten = dostounix(&dt, &tm);
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance >= 1000)) {
log_it(1, "\n ■ WWIV_INSTANCE set to %d. Can only be 1..999!", instance);
instance = 1;
}
} else
instance = 1;
sprintf(fn, "%s\\CONFIG.DAT", maindir);
f = sh_open1(fn, O_RDONLY | O_BINARY);
if (f < 0) {
output("\n ■ %s NOT FOUND.", fn);
cursor('R');
return EXIT_FAILURE;
}
sh_read(f, (void *) (&syscfg), sizeof(configrec));
sh_close(f);
read_groups();
if (ngroups == 0) {
output("\n ■ Unable to access newsgroup file NEWS.RC!");
cursor('R');
return EXIT_FAILURE;
} else {
sprintf(fn, "%sNEWS.RC", net_data);
sprintf(tempfn, "%sNEWS.BAK", net_data);
if (exist(tempfn))
unlink(tempfn);
copyfile(fn, tempfn);
}
if (stricmp(grouprec[0].groupname, "newsrc") == 0)
log_it(1, "\n ■ Retrieving current newsgroup listing from %s.",
serverhost);
else
log_it(MOREINFO, "\n ■ %u newsgroup%s defined in NEWS.RC.", ngroups,
ngroups == 1 ? "" : "s");
sprintf(fn, "%s\\NET.INI", maindir);
if ((fp = fsh_open(fn, "rt")) == NULL)
output("\n ■ Unable to read %s", fn);
else {
while (fgets(s, 100, fp)) {
stripspace(s);
if ((*s == ';') || (*s == '\n') || (*s == '['))
continue;
if (strlen(s) == 0)
continue;
if ((strnicmp(s, "POPNAME", 7) == 0) && (POPNAME[0] == 0)) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(POPNAME, ss);
}
}
if (strnicmp(s, "FWDNAME", 7) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(POPNAME, ss);
}
}
if ((strnicmp(s, "DOMAIN", 6) == 0) && (POPDOMAIN[0] == 0)) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(POPDOMAIN, ss);
}
}
if (strnicmp(s, "FWDDOM", 6) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(POPDOMAIN, ss);
}
}
if (strnicmp(s, "XPOSTS", 6) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
crossposts = atoi(ss);
if (crossposts > 99)
crossposts = 10;
}
}
if (strnicmp(s, "MORENEWS", 8) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
if ((ss[0] == 'n') || (ss[0] == 'N'))
MOREINFO = 0;
}
}
if (strnicmp(s, "BINXPOST", 8) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
if ((ss[0] == 'y') || (ss[0] == 'Y'))
binxpost = 1;
}
}
if (strnicmp(s, "NEWSRC_UPD", 9) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
if ((ss[0] == 'y') || (ss[0] == 'Y'))
newsrc_upd = 1;
}
}
if (strnicmp(s, "NEWSNAME", 8) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(NEWSNAME, ss);
}
}
if (strnicmp(s, "NEWSPASS", 8) == 0) {
ss = strtok(s, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(NEWSPASS, ss);
}
}
ss = NULL;
}
if (fp != NULL)
fclose(fp);
}
ok = 1;
if ((nntp_sock = netsocket(serverhost)) != NULL) {
bAuth = 1;
if (NEWSNAME[0]) {
if (!sendauthinfo(nntp_sock))
bAuth = 0;
}
if (bAuth)
ok = getnews(nntp_sock);
if (ok)
log_it(1, "\n ■ NEWS exited with an error.");
else
log_it(1, "\n ■ Normal NEWS completion.");
}
cd_to(maindir);
log_it(1, "\n ■ NEWS completed processing %d newsgroups", ngroups);
if (grouprec)
farfree(grouprec);
grouprec = NULL;
check_packets();
fcloseall();
cursor('R');
return ok;
}