home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B46.ZIP
/
NEWS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-10-05
|
51KB
|
1,896 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 <sys\stat.h>
#include <math.h>
#include "tcp.h"
#include "net.h"
#include "vardec.h"
#include "version.h"
#include "retcode.h"
#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 512
#define STR 129
#define WAIT_TIME 10
#define TRIES 100
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define NNTP_PORT 119
#define MAX_LOG 800
#define free_Mail_Socket(SOCK) if (SOCK!=NULL) { \
free(SOCK->sock); free(SOCK); SOCK=NULL; }
extern unsigned _stklen = 8192;
configrec syscfg;
char *version = "Freeware PPP Project News Retrieval " VERSION;
char _temp_buffer[BIGSTR];
char POPNAME[60], POPDOMAIN[60];
char cur_path[STRING], cur_from[STR], cur_subject[STRING], cur_replyto[STR];
char cur_newsgroups[STRING], cur_message_ID[STR], cur_organization[STR];
char cur_articleid[STR], cur_references[STR], cur_lines[STR], cur_date[STR];
char serverhost[81], maindir[MAXPATH], tmpdir[MAXPATH], net_data[121];
int instance, crossposts, multitasker = 0, NNTP_stat;
unsigned long cur_daten, reparticle, cur_numa, cur_first, cur_last;
unsigned short reply, sy;
typedef struct {
char groupname[60];
unsigned long lastread;
char subtype[8];
} GROUPFILEREC;
typedef struct Mail_Socket {
tcp_Socket *sock;
} Mail_Socket;
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)); \
cursor('R'); \
return 0; \
case -1: \
fprintf(stderr, "\n ! Timeout : %s", \
sockerr(PROTOCOL##_sock->sock)); \
cursor('R'); \
return 0; \
} \
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 len)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buffer, (unsigned) len));
}
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 len)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, len));
}
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));
}
void trim_log(void)
{
int num_lines, total_lines, kill_lines;
FILE *old_log, *new_log;
char ol[101], nl[101], s[121];
sprintf(ol, "%s\\NEWS.LOG", net_data);
sprintf(nl, "%s\\NEWS.ZZZ", net_data);
old_log = fopen(ol, "r");
new_log = fopen(nl, "a");
total_lines = 0;
if (old_log != NULL) {
while (!(fgets(s, 100, old_log) == NULL))
++total_lines;
rewind(old_log);
if (total_lines < MAX_LOG) {
fclose(old_log);
if (new_log != NULL)
fclose(new_log);
unlink(nl);
return;
}
kill_lines = total_lines - MAX_LOG;
num_lines = 0;
while ((fgets(s, 80, old_log)) && (num_lines < kill_lines))
num_lines++;
while ((strstr(s, "NEWS session") == NULL) && (num_lines < total_lines)) {
fgets(s, 80, old_log);
num_lines++;
}
fputs(s, new_log);
while ((!(fgets(s, 80, old_log) == NULL)))
fputs(s, new_log);
}
if (old_log != NULL)
fclose(old_log);
if (new_log != NULL)
fclose(new_log);
unlink(ol);
rename(nl, ol);
}
void ssm(char *s)
{
int f, i, i1;
char s1[161];
shortmsgrec sm;
configrec syscfg;
sprintf(s1, "CONFIG.DAT");
f = sh_open1(s1, O_RDONLY | O_BINARY);
if (f < 0)
return;
sh_read(f, (void *) (&syscfg), sizeof(configrec));
f = sh_close(f);
sprintf(s1, "%sSMW.DAT", syscfg.datadir);
f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
if (f < 0)
return;
i = (int) (filelength(f) / sizeof(shortmsgrec));
i1 = i - 1;
if (i1 >= 0) {
sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
sh_read(f, (void *) &sm, sizeof(shortmsgrec));
while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
--i1;
sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
sh_read(f, (void *) &sm, sizeof(shortmsgrec));
}
if ((sm.tosys) || (sm.touser))
++i1;
} else
i1 = 0;
sm.tosys = 0;
sm.touser = 1;
strncpy(sm.message, s, 80);
sm.message[80] = 0;
sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
sh_write(f, (void *) &sm, sizeof(shortmsgrec));
f = sh_close(f);
}
unsigned char *trimstr1(unsigned 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 send_ssm, char *fmt,...)
{
va_list v;
char s[255];
FILE *fp;
sprintf(s, "%s\\NEWS.LOG", net_data);
if ((fp = fsh_open(s, "at")) == NULL)
return 1;
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, fp);
fputs(s, stderr);
if (fp != NULL)
fclose(fp);
trimstr1(s);
if (send_ssm)
ssm(s);
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;
}
if (fp != NULL)
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 *dir, char *file)
{
char s[181], s1[181];
int i, ok;
sprintf(s, "%s\\%s", dir, file);
ok = 0;
for (i = 0; i < 1000 && !ok; i++) {
sprintf(s1, "%s\\P0-%u.NET", dir, i);
if (!exist(s1)) {
rename(s, s1);
ok = 1;
}
}
}
void check_packets(void)
{
char s[181];
int f1;
struct ffblk ff;
sprintf(s, "%s\\P0-*.%3.3d", net_data, instance);
f1 = findfirst(s, &ff, 0);
while (f1 == 0) {
rename_pend(net_data, ff.ff_name);
f1 = findnext(&ff);
}
}
void err_exit(int exitlevel, char *fmt,...)
{
va_list v;
char s[255];
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, stderr);
check_packets();
cursor('R');
exit(exitlevel);
}
void write_groups(int display)
{
int i;
char fn[160];
FILE *groupfp;
sprintf(fn, "%s\\NEWS.RC", net_data);
if ((groupfp = fsh_open(fn, "wt+")) == NULL) {
output("\n ■ Unable to open %s!", fn);
return;
} else {
if (display)
output("\n ■ Updating pointers...");
}
for (i = 0; i < ngroups; i++) {
if ((*grouprec[i].groupname) && (stricmp(grouprec[i].groupname, "newsrc") != 0)) {
fprintf(groupfp, "%s %ld %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 != NULL) {
sock_printf(NNTP_sock->sock, "QUIT");
sock_close(NNTP_sock->sock);
sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
}
sock_err:
return;
}
void far *mallocx(unsigned long l)
{
void *x;
char huge *xx;
if (!l)
l = 1;
x = farmalloc(l);
if (!x) {
output("\n ■ Unable to allocate %lu bytes of memory", l);
cursor('R');
exit(EXIT_FAILURE);
}
xx = (char huge *) x;
while (l) {
if (l > 32768L) {
memset((void *) xx, 0, (size_t) 32768L);
l -= 32768L;
xx += 32768L;
} else {
memset((void *) xx, 0, (size_t) l);
break;
}
}
return (x);
}
void far *malloca(unsigned long nbytes)
{
void *buf;
buf = malloc(nbytes + 1);
if (buf == NULL)
output("\n ■ Unable to allocate sufficient memory (%ld bytes)", nbytes);
return (buf);
}
void read_groups(void)
{
int i = 0, ok;
unsigned short sn;
char *ss, fn[101], fn1[160], tmp[101];
FILE *groupfp;
sprintf(fn1, "%s\\NEWS.RC", net_data);
ngroups = count_lines(fn1);
if (!ngroups)
return;
if (grouprec != NULL)
farfree((void *) grouprec);
grouprec = NULL;
grouprec = (GROUPFILEREC *) mallocx((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((void *) 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 != NULL) {
grouprec[i].lastread = atol(ss);
ss = strtok(NULL, " \n");
if (ss != NULL) {
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, "%s\\N%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 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);
if (reply == 411)
return 0;
else {
if (reply == 211) {
sscanf(_temp_buffer, "%hu %lu %lu %lu %s",
&reply, &cur_numa, &cur_first, &cur_last, &junk);
return 1;
} else {
if (reply == 480)
return -1;
else
log_it(0, "\n ■ Unknown cgroup response : %s", _temp_buffer);
return 1;
}
}
SOCK_READ_ERR(NNTP);
return 0;
}
void qexit(Mail_Socket * NNTP_sock, int n)
{
*_temp_buffer = 0;
if (n >= 10)
log_it(0, "\n ! Fatal NEWS error: check configuration!");
if (NNTP_sock != NULL) {
sock_printf(NNTP_sock->sock, "QUIT");
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
if (*_temp_buffer != '2')
log_it(0, "\n ■ Tried to quit host but failed");
free_Mail_Socket(NNTP_sock);
}
sock_err:
fcloseall();
cursor('R');
check_packets();
exit(EXIT_FAILURE);
}
void treat(char *text)
{
int pos = 0;
int len = strlen(text);
while ((pos < len) && (text[pos] != 10) && (text[pos] != 13)) {
if ((text[pos] < 32) || (text[pos] > 126)) {
memmove(text + pos, text + pos + 1, len - pos);
--len;
} else
++pos;
}
}
void name_packet(char *pktname)
{
int ok;
struct stat info;
unsigned int i;
ok = 0;
for (i = 0; ((i < 1000) && (!ok)); i++) {
sprintf(pktname, "%s\\P0-%u.%3.3d", net_data, i, instance);
if (stat(pktname, &info) == -1)
ok = 1;
}
}
int savebody(Mail_Socket * NNTP_sock, int cug, unsigned long cur_article, int *abort)
{
char s1[21], s2[21], buf[160], tpktname[MAXPATH];
unsigned int curpos, count, part;
char ch, spin[26], buffer[BIGSTR];
int i, place, len, done, spooltodisk;
unsigned long msgsize;
struct stat statbuf;
FILE *tpktfp;
strcpy(spin, "||//--\\\\");
place = count = spooltodisk = 0;
len = strlen(spin);
tpktfp = NULL;
*_temp_buffer = 0;
*abort = 0;
part = 1;
if ((strlen(grouprec[cug].subtype) == 1) && (*grouprec[cug].subtype == '0'))
spooltodisk = 1;
if (spooltodisk)
sprintf(tpktname, "%sNEWS%d.UUE", tmpdir, cug);
else {
sprintf(tpktname, "%sINPUT%d.MSG", tmpdir, part++);
if (stat(tpktname, &statbuf) == 0)
unlink(tpktname);
}
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, _temp_buffer, sizeof(_temp_buffer));
sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
if (reply == 423)
return 0;
else if (reply == 222) {
if (!spooltodisk) {
if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
fprintf(stderr, "\n ■ Unable to create temporary packet 1 %s", tpktname);
*abort = 1;
} else
fputs("\n", tpktfp);
} else {
if (tpktfp != NULL)
fclose(tpktfp);
if ((tpktfp = fsh_open(tpktname, "at+")) == NULL) {
fprintf(stderr, "\n ■ Unable to create temporary packet 2 %s", tpktname);
*abort = 1;
} else {
fputs("\n", tpktfp);
for (i = 0; i < 79; i++)
fputs("-", tpktfp);
fputs("\n", tpktfp);
sprintf(buf, "Art : %lu\n", cur_article);
fputs(buf, tpktfp);
if (*cur_date)
sprintf(buf, "Date : %s\n", cur_date);
else
sprintf(buf, "Date : Unknown\n");
fputs(buf, tpktfp);
if (*cur_replyto)
sprintf(buf, "From : %s\n", cur_replyto);
else
sprintf(buf, "From : Unknown\n");
fputs(buf, tpktfp);
if (*cur_subject)
sprintf(buf, "Subj : %s\n\n", cur_subject);
else
sprintf(buf, "Subj : Unknown\n");
fputs(buf, tpktfp);
}
}
fnsplit(tpktname, NULL, NULL, s1, s2);
if (!spooltodisk)
output("\n ■ Receiving message - [Esc] aborts - [Space] skips group [-]");
else
output("\n ■ Appending to %s%s - [Esc] aborts - [Space] skips group [-]", s1, s2);
msgsize = 0L;
curpos = 0L;
done = 0;
if (!*abort) {
while (!done) {
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) {
done = 1;
break;
} else {
strcpy(buffer, _temp_buffer);
treat(buffer);
strcat(buffer, "\n");
curpos = strlen(buffer);
if (!*abort)
fputs(buffer, tpktfp);
msgsize += curpos;
}
if (count++ > 5) {
output("\b\b%c]", spin[place++]);
if (len)
place %= len;
count = 0;
}
if ((msgsize > 30000L) && (!spooltodisk)) {
strcpy(buf, "\nContinued in next message...\n");
if (!*abort)
fputs(buf, tpktfp);
if (tpktfp != NULL)
fclose(tpktfp);
sprintf(tpktname, "%sINPUT%d.MSG", tmpdir, part++);
if (stat(tpktname, &statbuf) == 0)
unlink(tpktname);
if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
fprintf(stderr, "\n ■ Unable to create temporary packet 3 %s", tpktname);
*abort = 1;
}
backline();
output("\r ■ Breaking into %d%s part [ ]", (part - 1), ordinal_text(part - 1));
strcpy(buf, "\nContinued from previous message...\n");
if (!*abort)
fputs(buf, tpktfp);
msgsize = strlen(buf);
}
if (kbhit()) {
ch = (getch());
switch (ch) {
case 32:
output("\r ■ Skipping group... please wait until message is completed [-]");
*abort = 2;
break;
case 27:
output("\r ■ Abort detected... please wait until message is completed [-]");
*abort = 1;
break;
default:
break;
}
}
}
if (tpktfp != NULL)
fclose(tpktfp);
output("\b\bX]");
return 1;
} else
return -1;
} else
output("\n ■ Unknown BODY error : %s", _temp_buffer);
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 cur_article)
{
*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", cur_article);
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 == 423)
return 0;
else if (reply == 221) {
while (1) {
sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
if (strlen(_temp_buffer) >= BIGSTR)
_temp_buffer[BIGSTR] = '\0';
if (*_temp_buffer == '.' && _temp_buffer[1] == 0) {
if (!*cur_replyto)
strcpy(cur_replyto, cur_from);
return 1;
}
if (extract(cur_path, "Path:", _temp_buffer) ||
extract(cur_from, "From:", _temp_buffer) ||
extract(cur_subject, "Subject:", _temp_buffer) ||
extract(cur_replyto, "Reply-To:", _temp_buffer) ||
extract(cur_newsgroups, "Newsgroups:", _temp_buffer) ||
extract(cur_organization, "Organization:", _temp_buffer) ||
extract(cur_message_ID, "Message-ID:", _temp_buffer) ||
extract(cur_references, "References:", _temp_buffer) ||
extract(cur_lines, "Lines:", _temp_buffer) ||
extract(cur_date, "Date:", _temp_buffer))
continue;
}
} else
log_it(0, "\n ■ Unknown chead error : %s", _temp_buffer);
SOCK_READ_ERR(NNTP);
return 0;
}
Mail_Socket *netsocket(char *host)
{
Mail_Socket *NNTP_sock = NULL;
longword h;
*_temp_buffer = 0;
sock_init();
if (!(h = resolve(host)))
if (!(h = resolve(host)))
err_exit(EXIT_FAILURE, "\n ■ Could not resolve %s... aborting", host);
if ((NNTP_sock = (Mail_Socket *) malloc(sizeof(Mail_Socket))) == NULL)
err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
if ((NNTP_sock->sock = (tcp_Socket *) malloc(sizeof(tcp_Socket))) == NULL) {
free(NNTP_sock);
err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
}
if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
free_Mail_Socket(NNTP_sock);
err_exit(EXIT_FAILURE, "\n ■ TCP socket open failed... aborting");
}
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(0, "\n ■ Connection to %s accepted...", host);
break;
case 502:
free_Mail_Socket(NNTP_sock);
err_exit(EXIT_FAILURE, "\n ■ Connection to %s refused... try again later.", host);
break;
case 503:
free_Mail_Socket(NNTP_sock);
err_exit(EXIT_FAILURE, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
break;
default:
free_Mail_Socket(NNTP_sock);
err_exit(EXIT_FAILURE, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
break;
}
SOCK_READ_ERR(NNTP);
return (NNTP_sock);
}
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);
if (reply == 421)
return 0;
else
if (reply == 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;
} else
log_it(0, "\n ■ Unknown cnext error : %s", _temp_buffer);
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 sendauthinfo(Mail_Socket * NNTP_sock)
{
char s[MAXPATH], buf[STR], line[121], name[21], pass[31], *ss;
FILE *fp;
*_temp_buffer = 0;
output("\n ■ Server requested authentication information.");
sprintf(s, "%s\\NET.INI", maindir);
if ((fp = fsh_open(s, "rt")) == NULL) {
output("\n ■ Unable to open %s.", s);
return 0;
}
while (fgets(line, 80, fp)) {
ss = NULL;
stripspace(line);
if ((*line == ';') || (*line == '\n') || (*line == '['))
continue;
if (strlen(line) == 0)
continue;
if (strnicmp(line, "NEWSNAME", 8) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
name[0] = 0;
strcpy(name, ss);
}
}
if (strnicmp(line, "NEWSPASS", 8) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
pass[0] = 0;
strcpy(pass, ss);
}
}
}
if (fp != NULL)
fclose(fp);
if ((!*name) || (!*pass)) {
output("\n ■ NEWSNAME or NEWSPASS not properly defined!");
return 0;
}
while (1) {
sprintf(buf, "authinfo user %s", name);
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", pass);
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 retrieval session.");
return 0;
}
} else {
output("\n ■ Unknown AUTHINFO response %s.", _temp_buffer);
return 0;
}
}
SOCK_READ_ERR(NNTP);
return 0;
}
int saveactive(Mail_Socket * NNTP_sock, char *fn)
{
char s[181], group[256], act;
unsigned long to, from;
int count, done;
FILE *fp;
*_temp_buffer = 0;
if ((fp = fsh_open(fn, "w")) == NULL) {
perror(fn);
return 0;
}
done = 0;
while (!done) {
sock_printf(NNTP_sock->sock, "LIST");
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) {
count = 0;
while (1) {
if (count++ % 25 == 0)
output("\b\b\b\b\b\b\b%-7d", count);
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;
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);
}
log_it(0, "\n ■ %d total newsgroups available on %s", count, serverhost);
if (fp != NULL)
fclose(fp);
return 1;
} else {
if (reply == 480) {
if (fp != NULL)
fclose(fp);
return 0;
} else {
log_it(0, "\n ■ Unknown saveactive error : %s", _temp_buffer);
if (fp != NULL)
fclose(fp);
done = 1;
}
}
}
SOCK_READ_ERR(NNTP);
return 0;
}
int checkx(int cug)
{
char *ptr, *ptr2, *ptr3, buf[256];
int i, max;
sprintf(buf, "%s!%s", POPNAME, POPDOMAIN);
if (strstr(cur_path, buf) != 0) {
log_it(0, "\n ■ Local post \"%s\" skipped.", cur_subject);
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("\n ■ Skipping message - already posted in %s.",
grouprec[i].groupname);
return 0;
}
}
if ((crossposts > 0) && (max > crossposts)) {
output("\n ■ Skipping message - crossposted to more than %hu newsgroups.",
crossposts);
return 0;
}
}
return 1;
}
int postnews(Mail_Socket * NNTP_sock, int cug)
{
char s[181], s1[12], s2[5], fn[201], buf[STR], *ss;
int f1, nlines, len, tlen;
FILE *fp;
struct ffblk ff;
*_temp_buffer = 0;
sprintf(fn, "%s\\OUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
f1 = findfirst(fn, &ff, 0);
if (f1 != 0) {
log_it(0, "\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(1, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
else
log_it(0, "\n ■ Remote error: %s", _temp_buffer);
return 0;
}
output("\n ■ Posting article to %s\n", grouprec[cug].groupname);
sprintf(s, "%s\\OUTBOUND\\%s", net_data, ff.ff_name);
fp = fsh_open(s, "rb");
nlines = 0;
while (fgets(buf, 120, fp) != NULL) {
if (*buf == '.' && buf[1] == 0) {
buf[1] = '.';
buf[2] = 0;
}
tlen = 0;
len = strlen(buf);
while (tlen < len) {
if (!tcp_tick(NNTP_sock->sock)) {
if (fp != NULL)
fclose(fp);
output("\n ■ Connection reset by host");
return 1;
}
tlen += sock_fastwrite(NNTP_sock->sock, &buf[tlen], len - tlen);
}
backline();
output("\r ■ Lines sent : %d", ++nlines);
}
if (fp != NULL)
fclose(fp);
sock_printf(NNTP_sock->sock, ".\n");
output("\n ■ Awaiting acknowledgement - may take several minutes...");
log_it(0, "\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(0, "%s", _temp_buffer);
if (*_temp_buffer != '2') {
sscanf(_temp_buffer, "%hu %s", &reply, &buf);
if (reply == 441) {
ss = strtok(_temp_buffer, " ");
ss = strtok(NULL, " ");
if (atoi(ss) == 435)
unlink(s);
fnsplit(s, NULL, NULL, s1, s2);
log_it(0, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
} else
log_it(0, "\n ■ Remote error: %s", _temp_buffer);
} else {
if (unlink(s) == 0)
log_it(0, "\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 short max_on_sub(int cug)
{
int i, num_subs;
char fn[MAXPATH], subtype[12];
unsigned short max;
subboardrec sub;
FILE *fp;
max = 0;
if ((strlen(grouprec[cug].subtype) == 1) && (*grouprec[cug].subtype == '0'))
return max;
sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
if ((fp = fsh_open(fn, "rb")) == NULL) {
output("\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 = sub.maxmsgs;
output("\b\b\b\b%s (%s) - %hu posts.", sub.name, subtype, max);
break;
}
}
}
if (fp != NULL)
fclose(fp);
return max;
}
int getnews(Mail_Socket * NNTP_sock)
{
int f1, nup, nug, cug, abort, ok, done, firstrun, parts, bogus;
char *p, fn[201], mailname[121], reline[121], s[21], s1[21], pktname[121];
char ch, orig_subj[STRING], buf[STR];
unsigned int text_len;
unsigned short temptype;
unsigned long new_articles, max_articles;
net_header_rec nh;
struct ffblk ff;
FILE *fp;
abort = cug = bogus = 0;
if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
*grouprec[0].groupname = 0;
write_groups(0);
if (grouprec)
farfree((void *) grouprec);
sprintf(fn, "%s\\NEWSRC", net_data);
log_it(0, "\n ■ Creating newsgroup list : %s... ", fn);
if (!saveactive(NNTP_sock, fn)) {
if (sendauthinfo(NNTP_sock))
saveactive(NNTP_sock, fn);
}
nntp_shutdown(NNTP_sock);
free_Mail_Socket(NNTP_sock);
return 0;
}
nug = nup = 1;
cslave(NNTP_sock);
fp = NULL;
while ((cug < ngroups) && (!abort)) {
if (nup) {
nup = 0;
if (grouprec[cug].subtype) {
if (fp != NULL)
fclose(fp);
name_packet(pktname);
if ((fp = fsh_open(pktname, "wb")) == NULL) {
log_it(0, "\n ■ Unable to create %s!", pktname);
return 1;
} else {
fnsplit(pktname, NULL, NULL, s, s1);
output("\n ■ Creating new packet : %s%s", s, s1);
}
} else {
if (fp != NULL)
fclose(fp);
}
write_groups(1);
}
if (nug) {
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;
}
log_it(1, "\n ■ Error accessing newsgroup \"%s\".",
grouprec[cug].groupname);
if (++bogus >= 10) {
log_it(0, "\n ■ Too many invalid newsgroups... NEWS.RC error!");
return 1;
}
nug = 1;
break;
} else
break;
}
if (!nug) {
log_it(0, "\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(0, "no new articles.");
nug = 1;
write_groups(0);
} else {
new_articles = cur_last - grouprec[cug].lastread;
if (new_articles) {
log_it(0, "%lu new article%s.", new_articles,
new_articles == 1 ? "" : "s");
} else {
log_it(0, "no new articles.");
nug = 1;
write_groups(0);
}
if (new_articles > 250L) {
max_articles = 0L;
output("\n ■ Maximum posts - ");
max_articles = (long) max_on_sub(cug);
if (max_articles && (new_articles > max_articles)) {
log_it(0, "\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(0, "\n ■ No articles available in %s...",
grouprec[cug].groupname);
nug = 1;
continue;
}
}
}
} else {
if ((!cnext(NNTP_sock)) || (grouprec[cug].lastread > cur_last)) {
output("\n ■ End of new articles in %s",
grouprec[cug].groupname);
nug = 1;
write_groups(1);
}
}
while (kbhit()) {
ch = (getch());
switch (ch) {
case 27:
log_it(0, "\n ■ Aborting news retrieval session...");
if (fp != NULL)
fclose(fp);
nntp_shutdown(NNTP_sock);
free_Mail_Socket(NNTP_sock);
return 1;
case 32:
output("\n ■ Skipping group %s... ", grouprec[cug].groupname);
write_groups(0);
nug = 1;
break;
default:
break;
}
}
if (!nug) {
if ((chead(NNTP_sock, grouprec[cug].lastread)) && (checkx(cug))) {
if (*cur_subject)
treat(cur_subject);
else
strcpy(cur_subject, "No subject");
strcpy(orig_subj, cur_subject);
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("\n ■ [%lu/%lu] : %-55.55s ", grouprec[cug].lastread, cur_last, orig_subj);
ok = savebody(NNTP_sock, cug, grouprec[cug].lastread, &abort);
if (ok && grouprec[cug].subtype) {
sprintf(fn, "%sINPUT*.MSG", tmpdir);
done = 1;
parts = 0;
if (findfirst(fn, &ff, 0) == 0) {
parts = 1;
done = 0;
}
firstrun = 1;
while (!done) {
sprintf(fn, "%s%s", tmpdir, ff.ff_name);
f1 = sh_open1(fn, O_RDONLY | O_BINARY);
text_len = (unsigned int) filelength(f1);
if (text_len > 32000L) {
output("\n ■ Truncating %lu bytes from input file",
text_len - 32000L);
text_len = 32000;
}
if ((p = (char *) malloca(32767)) == NULL) {
log_it(0, "\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;
}
} else if (ok == -1) {
return 1;
}
}
++grouprec[cug].lastread;
if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
nup = 1;
if (abort == 2) {
write_groups(1);
nug = 1;
abort = 0;
}
}
if (nug) {
++cug;
if (((strlen(grouprec[cug].subtype) == 1) &&
(*grouprec[cug].subtype == '0')) && (grouprec[cug].subtype)) {
nup = 1;
} else {
if ((grouprec[cug - 1].subtype) &&
((strlen(grouprec[cug].subtype) == 1) &&
(*grouprec[cug].subtype == '0'))) {
if (fp != NULL)
fclose(fp);
}
}
}
}
if (fp != NULL)
fclose(fp);
if (abort)
log_it(0, "\n ■ Session aborted from keyboard");
write_groups(1);
nntp_shutdown(NNTP_sock);
free_Mail_Socket(NNTP_sock);
return 0;
}
main(int argc, char *argv[])
{
int ok, f;
char s[160], fn[MAXPATH], *ss;
FILE *fp;
struct tm *time_now;
struct date dt;
struct time tm;
time_t some;
Mail_Socket *nntp_sock = NULL;
cursor('S');
cursor('H');
output("\n ■ %s", version);
if (argc != 4)
err_exit(EXIT_FAILURE, "\n ■ Invalid arguments for %s\n", argv[0]);
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance >= 1000)) {
log_it(0, "\n ■ WWIV_INSTANCE set to %d. Can only be 1..999!", instance);
instance = 1;
}
} else
instance = 1;
gettime(&tm);
getdate(&dt);
cur_daten = dostounix(&dt, &tm);
get_dir(maindir, 0);
strcpy(net_data, argv[1]);
detect_multitask();
time(&some);
time_now = localtime(&some);
strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
time_now);
sprintf(fn, "%s\\NEWS.LOG", net_data);
if ((fp = fsh_open(fn, "at")) != NULL) {
fprintf(fp, s);
fclose(fp);
}
sprintf(tmpdir, "%s\\SPOOL\\", net_data);
sy = atoi(argv[3]);
sprintf(s, "%s\\CONFIG.DAT", maindir);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0)
err_exit(EXIT_FAILURE, "\n ■ %s NOT FOUND.", s);
sh_read(f, (void *) (&syscfg), sizeof(configrec));
sh_close(f);
sprintf(s, "%s\\NEWS.RC", net_data);
read_groups();
if (ngroups == 0)
err_exit(EXIT_FAILURE, "\n ■ Unable to access newsgroup file: %s!", s);
if (stricmp(grouprec[0].groupname, "newsrc") == 0)
log_it(0, "\n ■ Retrieving current newsgroup listing from %s.",
serverhost);
else
log_it(0, "\n ■ %u newsgroup%s defined in %s.", ngroups,
ngroups == 1 ? "" : "s", s);
crossposts = 10;
POPNAME[0] = 0;
POPDOMAIN[0] = 0;
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;
}
}
ss = NULL;
}
if (fp != NULL)
fclose(fp);
}
nntp_sock = netsocket(argv[2]);
ok = getnews(nntp_sock);
if (ok)
log_it(1, "\n ■ NEWS exited with an error.");
else
log_it(0, "\n ■ Normal NEWS completion.");
if (grouprec)
farfree((void *) grouprec);
grouprec = NULL;
cd_to(maindir);
fcloseall();
log_it(0, "\n ■ NEWS succesfully completed processing %d newsgroups", ngroups);
trim_log();
return ok;
}