home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B32.ZIP / NEWS.C < prev    next >
Text File  |  1997-07-02  |  51KB  |  1,886 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <ctype.h>
  4. #include <process.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <errno.h>
  10. #include <fcntl.h>
  11. #include <io.h>
  12. #include <dos.h>
  13. #include <share.h>
  14. #include <dir.h>
  15. #include <alloc.h>
  16. #include <sys\stat.h>
  17. #include <math.h>
  18. #include "tcp.h"
  19. #include "pop.h"
  20. #include "net.h"
  21. #include "vardec.h"
  22. #include "version.h"
  23.  
  24. extern unsigned _stklen = 8192;
  25.  
  26. #define SHARE_LEVEL 10
  27. #define WAIT_TIME 10
  28. #define TRIES 100
  29.  
  30. #define MT_DESQVIEW 0x01
  31. #define MT_WINDOWS  0x02
  32. #define MT_OS2      0x04
  33. #define MT_NB       0x40
  34.  
  35. #define BIGSTR 4096
  36. #define STRING 512
  37. #define STR 129
  38. #define WAIT_TIME 10
  39. #define TRIES 100
  40. #define NUL '\0'
  41. #define LAST(s) s[strlen(s)-1]
  42. #define NNTP_PORT 119
  43. #define MAX_LOG 800
  44.  
  45. #define free_Mail_Socket(SOCK) if (SOCK!=NULL) {     \
  46.   farfree(SOCK->sock); farfree(SOCK); SOCK=NULL; }
  47.  
  48. tcp_Socket nntpsock;
  49. configrec syscfg;
  50. subboardrec *subboards;
  51.  
  52. static int NNTP_stat;
  53.  
  54. unsigned short reply;
  55. unsigned long reparticle;
  56.  
  57. char serverhost[81], newsrc[81], fromline[121], smtppath[81];
  58. char maindir[181], tmpdir[201], net_data[181];
  59. char *version = "Freeware PPP News Retrieval " VERSION;
  60.  
  61. char cur_gname[STRING], tpktname[121];
  62. char msgto[STRING], msgarea[STRING];
  63. unsigned long cur_numa, cur_first, cur_last;
  64.  
  65. unsigned long cur_article;
  66. char cur_articleid[STRING];
  67. char cur_path[STRING], cur_from[STRING], cur_subject[STRING], cur_replyto[STRING];
  68. char cur_newsgroups[STRING], cur_message_ID[STRING], cur_organization[STRING], cur_references[STRING], cur_lines[STR], cur_date[STRING];
  69. unsigned short sy, crossposts;
  70. int instance, multitasker = 0, SOCK_DELAY;
  71.  
  72. typedef struct {
  73.   char groupname[60];
  74.   unsigned long lastread;
  75.   char subtype[8];
  76. } GROUPFILEREC;
  77.  
  78. GROUPFILEREC *grouprec;
  79. int ngroups;
  80.  
  81. int bogus = 0;
  82.  
  83. #define SOCK_READ_ERR(SOCK) sock_err:                                     \
  84.   switch (NNTP_stat) {                                                    \
  85.     case 1 :                                                              \
  86.       write_groups(1);                                                    \
  87.       log_it(0, "\n ! Connection closed : %s", sockerr(NNTP_sock->sock)); \
  88.       free_Mail_Socket(SOCK);                                             \
  89.       fcloseall();                                                        \
  90.       cursor('R');                                                        \
  91.       exit(EXIT_FAILURE);                                                 \
  92.     case -1:                                                              \
  93.       write_groups(1);                                                    \
  94.       log_it(0, "\n ! Session error: %s", sockerr(NNTP_sock->sock));      \
  95.       free_Mail_Socket(SOCK);                                             \
  96.       fcloseall();                                                        \
  97.       cursor('R');                                                        \
  98.       exit(EXIT_FAILURE);                                                 \
  99.   }                                                                       \
  100.  
  101. char *texth[] = {"th", "st", "nd", "rd"};
  102.  
  103. char *ordinal_text(int number)
  104. {
  105.   if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
  106.     number = 0;
  107.   return texth[number];
  108. }
  109.  
  110. static unsigned cursize;
  111.  
  112. void cursor(int tmp)
  113. {
  114.   union REGS inregs, outregs;
  115.  
  116.   switch (toupper(tmp)) {
  117.     case 'S':                               /* Save */
  118.       inregs.h.ah = 3;
  119.       inregs.h.bh = 0;
  120.       int86(0x10, &inregs, &outregs);
  121.       cursize = outregs.x.cx;
  122.       break;
  123.     case 'R':                               /* Restore */
  124.       inregs.h.ah = 1;
  125.       inregs.x.cx = cursize;
  126.       int86(0x10, &inregs, &outregs);
  127.       break;
  128.     case 'H':                               /* Hide */
  129.       inregs.h.ah = 1;
  130.       inregs.h.ch = 0x20;
  131.       int86(0x10, &inregs, &outregs);
  132.       break;
  133.     case 'N':                               /* Normal */
  134.       inregs.h.ah = 1;
  135.       inregs.h.ch = 6;
  136.       inregs.h.cl = 7;
  137.       int86(0x10, &inregs, &outregs);
  138.       break;
  139.   }
  140. }
  141.  
  142. void dv_pause(void)
  143. {
  144.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  145.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  146.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  147. }
  148.  
  149. void win_pause(void)
  150. {
  151.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  152. }
  153.  
  154. int get_dos_version(void)
  155. {
  156.   _AX = 0x3000;
  157.   geninterrupt(0x21);
  158.   if (_AX % 256 >= 10) {
  159.     multitasker |= MT_OS2;
  160.   }
  161.   return (_AX);
  162. }
  163.  
  164. int get_dv_version(void)
  165. {
  166.   int v;
  167.  
  168.   if (multitasker & MT_OS2)
  169.     return 0;
  170.   _AX = 0x2b01;
  171.   _CX = 0x4445;
  172.   _DX = 0x5351;
  173.   geninterrupt(0x21);
  174.   if (_AL == 0xff) {
  175.     return 0;
  176.   } else {
  177.     v = _BX;
  178.     multitasker |= MT_DESQVIEW;
  179.     return v;
  180.   }
  181. }
  182.  
  183. int get_win_version(void)
  184. {
  185.   int v = 0;
  186.  
  187.   __emit__(0x55, 0x06, 0x53);
  188.   _AX = 0x352f;
  189.   geninterrupt(0x21);
  190.   _AX = _ES;
  191.   if (_AX | _BX) {
  192.     _AX = 0x1600;
  193.     geninterrupt(0x2f);
  194.     v = _AX;
  195.     if (v % 256 <= 1)
  196.       v = 0;
  197.   }
  198.   __emit__(0x5b, 0x07, 0x5d);
  199.   if (v != 0)
  200.     multitasker |= MT_WINDOWS;
  201.   return (v);
  202. }
  203.  
  204. int get_nb_version(void)
  205. {
  206.   _AX = 0;
  207.   geninterrupt(0x2A);
  208.   return (_AH);
  209. }
  210.  
  211. void detect_multitask(void)
  212. {
  213.   get_dos_version();
  214.   get_win_version();
  215.   get_dv_version();
  216.   if (multitasker < 2)
  217.     if (get_nb_version())
  218.       multitasker = MT_NB;
  219. }
  220.  
  221. void giveup_timeslice(void)
  222. {
  223.   if (multitasker) {
  224.     switch (multitasker) {
  225.  case 1:
  226.  case 3:
  227.         dv_pause();
  228.         break;
  229.       case 2:
  230.       case 4:
  231.       case 5:
  232.       case 6:
  233.       case 7:
  234.         win_pause();
  235.         break;
  236.       default:
  237.         break;
  238.     }
  239.   }
  240. }
  241.  
  242. void output(char *fmt, ...)
  243. {
  244.   va_list v;
  245.   char s[255];
  246.  
  247.   va_start(v, fmt);
  248.   vsprintf(s, fmt, v);
  249.   va_end(v);
  250.   fputs(s, stderr);
  251. }
  252.  
  253. void backline(void)
  254. {
  255.   int i;
  256.  
  257.   output(" ");
  258.   for (i = wherex(); i > 0; i--)
  259.     output("\b \b");
  260. }
  261.  
  262. void cd_to(char *s)
  263. {
  264.   char *s1;
  265.   int i, db;
  266.  
  267.   s1 = s;
  268.   i = strlen(s1) - 1;
  269.   db = (s1[i] == '\\');
  270.   if (i == 0)
  271.     db = 0;
  272.   if ((i == 2) && (s1[1] == ':'))
  273.     db = 0;
  274.   if (db)
  275.     s1[i] = 0;
  276.   chdir(s1);
  277.   if (s[1] == ':')
  278.     setdisk(s[0] - 'A');
  279. }
  280.  
  281. void get_dir(char *s, int be)
  282. {
  283.   strcpy(s, "X:\\");
  284.   s[0] = 'A' + getdisk();
  285.   getcurdir(0, s + 3);
  286.   if (be) {
  287.     if (s[strlen(s) - 1] != '\\')
  288.       strcat(s, "\\");
  289.   }
  290. }
  291.  
  292. int sh_write(int handle, void *buffer, unsigned long len)
  293. {
  294.   if (handle == -1) {
  295.     return (-1);
  296.   }
  297.   return (write(handle, buffer, (unsigned) len));
  298. }
  299.  
  300. int sh_open(char *path, int file_access, unsigned fmode)
  301. {
  302.   int handle, count, share;
  303.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  304.  
  305.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  306.     share = SH_DENYRW;
  307.   } else {
  308.     share = SH_DENYWR;
  309.   }
  310.   handle = open(path, file_access | share, fmode);
  311.   if (handle < 0) {
  312.     count = 1;
  313.     fnsplit(path, drive, dir, file, ext);
  314.     if (access(path, 0) != -1) {
  315.       delay(WAIT_TIME);
  316.       handle = open(path, file_access | share, fmode);
  317.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  318.         if (count % 2)
  319.           delay(WAIT_TIME);
  320.         else
  321.           giveup_timeslice();
  322.         count++;
  323.         handle = open(path, file_access | share, fmode);
  324.       }
  325.     }
  326.   }
  327.   return (handle);
  328. }
  329.  
  330. int sh_open1(char *path, int access)
  331. {
  332.   unsigned fmode;
  333.  
  334.   fmode = 0;
  335.   if ((access & O_RDWR) || (access & O_WRONLY))
  336.     fmode |= S_IWRITE;
  337.   if ((access & O_RDWR) || (access & O_RDONLY))
  338.     fmode |= S_IREAD;
  339.   return (sh_open(path, access, fmode));
  340. }
  341.  
  342. int sh_close(int f)
  343. {
  344.   if (f != -1)
  345.     close(f);
  346.   return (-1);
  347. }
  348.  
  349. int sh_read(int handle, void *buf, unsigned len)
  350. {
  351.   if (handle == -1) {
  352.     return (-1);
  353.   }
  354.   return (read(handle, buf, len));
  355. }
  356.  
  357. long sh_lseek(int handle, long offset, int fromwhere)
  358. {
  359.   if (handle == -1) {
  360.     return (-1L);
  361.   }
  362.   return (lseek(handle, offset, fromwhere));
  363. }
  364.  
  365. FILE *fsh_open(char *path, char *fmode)
  366. {
  367.   FILE *f;
  368.   int count, share, md, fd;
  369.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  370.  
  371.   share = SH_DENYWR;
  372.   md = 0;
  373.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  374.     share = SH_DENYRD;
  375.     md = O_RDWR | O_CREAT | O_TRUNC;
  376.   } else
  377.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  378.     share = SH_DENYRD;
  379.     md = O_RDWR | O_CREAT;
  380.   } else {
  381.     md = O_RDONLY;
  382.   }
  383.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  384.     md |= O_BINARY;
  385.   }
  386.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  387.     md &= ~O_RDONLY;
  388.     md |= O_RDWR;
  389.     share = SH_DENYRD;
  390.   }
  391.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  392.   if (fd < 0) {
  393.     count = 1;
  394.     fnsplit(path, drive, dir, file, ext);
  395.     if ((access(path, 0)) != -1) {
  396.       delay(WAIT_TIME);
  397.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  398.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  399.         delay(WAIT_TIME);
  400.         count++;
  401.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  402.       }
  403.     }
  404.   }
  405.   if (fd > 0) {
  406.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  407.       sh_lseek(fd, 0L, SEEK_END);
  408.     f = fdopen(fd, fmode);
  409.     if (!f) {
  410.       close(fd);
  411.     }
  412.   } else
  413.     f = 0;
  414.   return (f);
  415. }
  416.  
  417. size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
  418. {
  419.  
  420.   if (stream == NULL) {
  421.     return (0);
  422.   }
  423.   return (fwrite(ptr, size, n, stream));
  424. }
  425.  
  426. void trim_log(void)
  427. {
  428.   int num_lines, total_lines, kill_lines;
  429.   FILE *old_log, *new_log;
  430.   char ol[81], nl[81], s[81];
  431.  
  432.   sprintf(ol, "%s\\NEWS.LOG", net_data);
  433.   sprintf(nl, "%s\\NEWS.ZZZ", net_data);
  434.  
  435.   old_log = fopen(ol, "r");
  436.   new_log = fopen(nl, "a");
  437.  
  438.   total_lines = 0;
  439.   if (old_log != NULL) {
  440.     while (!(fgets(s, 81, old_log) == NULL)) {
  441.       total_lines += 1;
  442.     }
  443.     rewind(old_log);
  444.     if (total_lines < MAX_LOG) {
  445.       fclose(old_log);
  446.       fclose(new_log);
  447.       unlink(nl);
  448.       return;
  449.     }
  450.     kill_lines = total_lines - MAX_LOG;
  451.     num_lines = 0;
  452.     while (!(fgets(s, 81, old_log) == NULL) && (num_lines < kill_lines)) {
  453.       num_lines++;
  454.     }
  455.     while ((strstr(s, "NEWS session") == NULL) && (num_lines < total_lines)) {
  456.       fgets(s, 81, old_log);
  457.       num_lines++;
  458.     }
  459.     fputs(s, new_log);
  460.     while ((!(fgets(s, 81, old_log) == NULL))) {
  461.       fputs(s, new_log);
  462.     }
  463.   }
  464.   fclose(old_log);
  465.   fclose(new_log);
  466.   unlink(ol);
  467.   rename(nl, ol);
  468. }
  469.  
  470. void ssm(char *s)
  471. {
  472.   int f, i, i1;
  473.   char s1[161];
  474.   shortmsgrec sm;
  475.   configrec syscfg;
  476.  
  477.   sprintf(s1, "CONFIG.DAT");
  478.   f = sh_open1(s1, O_RDWR | O_BINARY);
  479.   if (f < 0)
  480.     return;
  481.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  482.   sh_close(f);
  483.   sprintf(s1, "%sSMW.DAT", syscfg.datadir);
  484.   f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  485.   if (f < 0)
  486.     return;
  487.   i = (int) (filelength(f) / sizeof(shortmsgrec));
  488.   i1 = i - 1;
  489.   if (i1 >= 0) {
  490.     sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  491.     sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  492.     while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
  493.       --i1;
  494.       sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  495.       sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  496.     }
  497.     if ((sm.tosys) || (sm.touser))
  498.       ++i1;
  499.   } else
  500.     i1 = 0;
  501.   sm.tosys = 0;
  502.   sm.touser = 1;
  503.   strncpy(sm.message, s, 80);
  504.   sm.message[80] = 0;
  505.   sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  506.   sh_write(f, (void *) &sm, sizeof(shortmsgrec));
  507.   sh_close(f);
  508. }
  509.  
  510.  
  511. int log_it(int send_ssm, char *fmt,...)
  512. {
  513.   va_list v;
  514.   char s[255];
  515.   FILE *fp;
  516.  
  517.   sprintf(s, "%s\\NEWS.LOG", net_data);
  518.   if ((fp = fsh_open(s, "at")) == NULL)
  519.     return 1;
  520.   va_start(v, fmt);
  521.   vsprintf(s, fmt, v);
  522.   va_end(v);
  523.   fputs(s, fp);
  524.   fputs(s, stderr);
  525.   fclose(fp);
  526.   if (send_ssm)
  527.     ssm(s);
  528.   return 0;
  529. }
  530.  
  531.  
  532. int count_lines(char *s)
  533. {
  534.   FILE *fp;
  535.   char fn[201];
  536.   unsigned int nl = 0;
  537.   const int NEWLINE = '\n';
  538.   int c;
  539.  
  540.   strcpy(fn, s);
  541.   fp = fsh_open(fn, "rt");
  542.   if (fp == NULL) {
  543.     output("\n ■ Cannot open %s", fn);
  544.     return 0;
  545.   }
  546.   while ((c = getc(fp)) != EOF) {
  547.     if (c == NEWLINE)
  548.       ++nl;
  549.   }
  550.   fclose(fp);
  551.   return nl;
  552. }
  553.  
  554. static unsigned char *trimstr1(unsigned char *s)
  555. {
  556.   int i;
  557.   static char *whitespace = " \r\n\t";
  558.  
  559.   i = strlen(s);
  560.   while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
  561.     --i;
  562.   while ((i > 0) && (_fstrchr(whitespace, *s))) {
  563.     memmove(s, s + 1, --i);
  564.   }
  565.   s[i] = 0;
  566.   return (s);
  567. }
  568.  
  569. void usleep(void)
  570. {
  571.   tcp_tick(NULL);                           /* occasionally process something */
  572. }
  573.  
  574. int exist(char *s)
  575. {
  576.   int i;
  577.   struct ffblk ff;
  578.  
  579.   i = findfirst(s, &ff, 0);
  580.   if (i)
  581.     return (0);
  582.   else
  583.     return (1);
  584. }
  585.  
  586. void rename_pend(char *dir, char *file)
  587. {
  588.   char s[181], s1[181];
  589.   int i, ok;
  590.  
  591.   sprintf(s, "%s\\%s", dir, file);
  592.   ok = 0;
  593.   for (i = 0; i < 1000 && !ok; i++) {
  594.     sprintf(s1, "%s\\P0-%u.NET", dir, i);
  595.     if (!exist(s1)) {
  596.       rename(s, s1);
  597.       ok = 1;
  598.     }
  599.   }
  600. }
  601.  
  602. void check_packets(void)
  603. {
  604.   char s[181];
  605.   int f1;
  606.   struct ffblk ff;
  607.  
  608.   sprintf(s, "%s\\P0-*.%3.3d", net_data, instance);
  609.   f1 = findfirst(s, &ff, 0);
  610.   while (f1 == 0) {
  611.     rename_pend(net_data, ff.ff_name);
  612.     f1 = findnext(&ff);
  613.   }
  614. }
  615.  
  616.  
  617. void err_exit(int exitlevel, char *fmt,...)
  618. {
  619.   va_list v;
  620.   char s[255];
  621.  
  622.   va_start(v, fmt);
  623.   vsprintf(s, fmt, v);
  624.   va_end(v);
  625.   fputs(s, stderr);
  626.   check_packets();
  627.   cursor('R');
  628.   exit(exitlevel);
  629. }
  630.  
  631. void write_groups(int display)
  632. {
  633.   int i;
  634.   FILE *groupfp;
  635.  
  636.   groupfp = fsh_open(newsrc, "wt");
  637.   if (!groupfp) {
  638.     output("\n ■ Unable to open %s!", newsrc);
  639.     return;
  640.   } else {
  641.     if (display)
  642.       output("\n ■ Updating pointers in %s...", newsrc);
  643.   }
  644.   for (i = 0; i < ngroups; i++) {
  645.     if ((grouprec[i].groupname[0]) && (stricmp(grouprec[i].groupname, "newsrc") != 0)) {
  646.       fprintf(groupfp, "%s %ld %s\n", grouprec[i].groupname,
  647.               grouprec[i].lastread, grouprec[i].subtype);
  648.     }
  649.   }
  650.   fclose(groupfp);
  651. }
  652.  
  653. void far *mallocx(unsigned long l)
  654. {
  655.   void *x;
  656.   char huge *xx;
  657.  
  658.   if (!l)
  659.     l = 1;
  660.   x = farmalloc(l);
  661.   if (!x) {
  662.     output("\n ■ Unable to allocate %lu bytes of memory", l);
  663.     cursor('R');
  664.     exit(EXIT_FAILURE);
  665.   }
  666.   xx = (char huge *) x;
  667.   while (l) {
  668.     if (l > 32768L) {
  669.       memset((void *) xx, 0, (size_t) 32768L);
  670.       l -= 32768L;
  671.       xx += 32768L;
  672.     } else {
  673.       memset((void *) xx, 0, (size_t) l);
  674.       break;
  675.     }
  676.   }
  677.   return (x);
  678. }
  679.  
  680.  
  681. void far *malloca(unsigned long nbytes)
  682. {
  683.   void *buf;
  684.  
  685.   buf = malloc((int) nbytes + 1);
  686.   if (buf == NULL)
  687.     output("\n ■ Unable to allocate sufficient memory (%ld bytes)", nbytes);
  688.   return (buf);
  689. }
  690.  
  691. void nntp_shutdown(Mail_Socket * NNTP_sock)
  692. {
  693.   sock_printf(NNTP_sock->sock, "QUIT");
  694.   sock_close(NNTP_sock->sock);
  695.   sock_wait_closed(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  696. sock_err:
  697.   return;
  698. }
  699.  
  700.  
  701. void read_groups(void)
  702. {
  703.   int i = 0, ok;
  704.   unsigned short sn;
  705.   char *ss, fn[101], tmp[101];
  706.   FILE *groupfp;
  707.  
  708.   if (grouprec)
  709.     free((void *) grouprec);
  710.   grouprec = NULL;
  711.   ngroups = count_lines(newsrc);
  712.   if (!ngroups)
  713.     return;
  714.   grouprec = (GROUPFILEREC *) mallocx((ngroups + 1) * sizeof(GROUPFILEREC));
  715.   if (!grouprec) {
  716.     ngroups = 0;
  717.     output("\n ■ Unable to allocate memory for reading NEWS.RC!");
  718.     return;
  719.   }
  720.   groupfp = fsh_open(newsrc, "rt");
  721.   if (!groupfp) {
  722.     free((void *) grouprec);
  723.     ngroups = 0;
  724.     return;
  725.   }
  726.   while (fgets(tmp, 120, groupfp)) {
  727.     if (tmp[0]) {
  728.       if (strncmpi(tmp, "newsrc", 6) == 0) {
  729.         strcpy(grouprec[i].groupname, "newsrc");
  730.         ++i;
  731.       } else {
  732.         ss = strtok(tmp, " ");
  733.         strcpy(grouprec[i].groupname, ss);
  734.         ss = strtok(NULL, " ");
  735.         if (ss != NULL) {
  736.           grouprec[i].lastread = atol(ss);
  737.           ss = strtok(NULL, " \n");
  738.           if (ss != NULL) {
  739.             strcpy(grouprec[i].subtype, strupr(ss));
  740.             ++i;
  741.           }
  742.         }
  743.       }
  744.     }
  745.   }
  746.   ngroups = i;
  747.   fclose(groupfp);
  748.   for (i = 0; i < ngroups; i++) {
  749.     if ((grouprec[i].subtype) && (atoi(grouprec[i].subtype) != 0)) {
  750.       sprintf(fn, "%s\\N%s.NET", net_data, grouprec[i].subtype);
  751.       if (exist(fn)) {
  752.         groupfp = fsh_open(fn, "rt");
  753.         ok = 0;
  754.         while ((fgets(tmp, 25, groupfp)) && !ok) {
  755.           sn = atoi(tmp);
  756.           if (sn == 32767)
  757.             ok = 1;
  758.         }
  759.         fclose(groupfp);
  760.         if (!ok)
  761.           log_it(1, "\n ■ @32767 not list as a subscriber in N%s.NET!",
  762.                  grouprec[i].subtype);
  763.       }
  764.     }
  765.   }
  766. }
  767.  
  768. int cgroup(Mail_Socket * NNTP_sock, char *s)
  769. {
  770.   static char _temp_buffer[STRING];
  771.  
  772.   sock_printf(NNTP_sock->sock, "GROUP %s", s);
  773.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  774.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  775.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  776.   if (reply == 411)
  777.     return 1;
  778.   else {
  779.     if (reply == 211) {
  780.       sscanf(_temp_buffer, "%hu %lu %lu %lu %s",
  781.              &reply, &cur_numa, &cur_first, &cur_last, &cur_gname);
  782.       return 0;
  783.     } else {
  784.       if (reply == 480)
  785.         return 2;
  786.       else
  787.         log_it(0, "\n ■ Unknown cgroup response : %s", _temp_buffer);
  788.       return 1;
  789.     }
  790.   }
  791.   SOCK_READ_ERR(NNTP_sock);
  792.   return -1;
  793. }
  794.  
  795. int cstat(Mail_Socket * NNTP_sock, unsigned long i)
  796. {
  797.   char *p, *q;
  798.   static char _temp_buffer[STRING];
  799.  
  800.   sock_printf(NNTP_sock->sock, "STAT %lu", i);
  801.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  802.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  803.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  804.   if (reply == 423)
  805.     return -1;
  806.   else
  807.     if (reply == 223) {
  808.     cur_article = reparticle;
  809.     p = _temp_buffer;
  810.     q = cur_articleid;
  811.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  812.       p++;
  813.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  814.       *q++ = *p++;
  815.     *q++ = '>';
  816.     *q++ = '\0';
  817.     return 0;
  818.     }
  819.   else
  820.     log_it(0, "\n ■ Unknown cstat error : %s", _temp_buffer);
  821.   SOCK_READ_ERR(NNTP_sock);
  822.   return -1;
  823. }
  824.  
  825. void qexit(Mail_Socket * NNTP_sock, int n)
  826. {
  827.   static char _temp_buffer[STR];
  828.  
  829.   if (n >= 10)
  830.     log_it(0, "\n ! Fatal NEWS error: check configuration!");
  831.   fflush(stdout);
  832.   sock_printf(NNTP_sock->sock, "QUIT");
  833.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  834.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  835.   if (*_temp_buffer != '2')
  836.     log_it(0, "\n ■ Tried to quit host but failed");
  837. sock_err:
  838.   cursor('R');
  839.   check_packets();
  840.   fcloseall();
  841.   free_Mail_Socket(NNTP_sock);
  842.   exit(n);
  843. }
  844.  
  845. void treat(char *str)
  846. {
  847.   char *obuf, *nbuf;
  848.  
  849.   if (*str) {
  850.     for (obuf = str, nbuf = str; *obuf && obuf; ++obuf) {
  851.       if (((*obuf >= 32) && (*obuf <= 126)) || (*obuf == 10) || (*obuf == 9)) {
  852.         *nbuf++ = *obuf;
  853.       }
  854.     }
  855.   }
  856.   *nbuf = 0;
  857. }
  858.  
  859. void name_packet(char *pktname)
  860. {
  861.   int ok;
  862.   struct stat info;
  863.   unsigned i;
  864.  
  865.   ok = 0;
  866.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  867.     sprintf(pktname, "%s\\P0-%u.%3.3d", net_data, i, instance);
  868.     if (stat(pktname, &info) == -1)
  869.       ok = 1;
  870.   }
  871. }
  872.  
  873. int savebody(Mail_Socket * NNTP_sock, int cug, int *abort)
  874. {
  875.   char s1[21], s2[21], ch;
  876.   unsigned int curpos, count, part;
  877.   char spin[26];
  878.   int i, place, len, spooltodisk;
  879.   unsigned long msgsize;
  880.   struct stat statbuf;
  881.   FILE *tpktfp = NULL;
  882.   static char _temp_buffer[BIGSTR];
  883.  
  884.   strcpy(spin, "||//--\\\\");
  885.   place = count = spooltodisk = 0;
  886.   len = strlen(spin);
  887.  
  888.   if ((strlen(grouprec[cug].subtype) == 1) &&
  889.       (grouprec[cug].subtype[0] == '0'))
  890.     spooltodisk = 1;
  891.   part = 1;
  892.   if (spooltodisk)
  893.     sprintf(tpktname, "%s\\NEWS%d.UUE", tmpdir, cug);
  894.   else {
  895.     sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  896.     if (stat(tpktname, &statbuf) == 0)
  897.       unlink(tpktname);
  898.   }
  899.   sock_printf(NNTP_sock->sock, "BODY %lu", cur_article);
  900.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  901.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  902.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  903.   if (reply == 423)
  904.     return -1;
  905.   else {
  906.     if (reply == 222) {
  907.       if (!spooltodisk) {
  908.         if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
  909.           log_it(0, "\n ■ Unable to create temporary packet %s", tpktname);
  910.           qexit(NNTP_sock, 1);
  911.         } else {
  912.           strcpy(_temp_buffer, "\n");
  913.           fputs(_temp_buffer, tpktfp);
  914.         }
  915.       } else {
  916.         if (tpktfp)
  917.           fclose(tpktfp);
  918.         if ((tpktfp = fsh_open(tpktname, "at+")) == NULL) {
  919.           log_it(0, "\n ■ Unable to create temporary packet %s", tpktname);
  920.           qexit(NNTP_sock, 1);
  921.         } else {
  922.           fputs("\n", tpktfp);
  923.           for (i = 0; i < 79; i++)
  924.             fputs("-", tpktfp);
  925.           fputs("\n", tpktfp);
  926.           sprintf(_temp_buffer, "Art  : %lu\n", cur_article);
  927.           fputs(_temp_buffer, tpktfp);
  928.           sprintf(_temp_buffer, "Date : %s\n", cur_date);
  929.           fputs(_temp_buffer, tpktfp);
  930.           sprintf(_temp_buffer, "From : %s\n", cur_replyto);
  931.           fputs(_temp_buffer, tpktfp);
  932.           sprintf(_temp_buffer, "Subj : %s\n\n", cur_subject);
  933.           fputs(_temp_buffer, tpktfp);
  934.         }
  935.       }
  936.       fnsplit(tpktname, NULL, NULL, s1, s2);
  937.       if (!spooltodisk)
  938.         output("\n ■ Receiving message - <Esc> aborts - <Space> skips group [-]");
  939.       else
  940.         output("\n ■ Appending to %s%s - <Esc> aborts - <Space> skips group [-]", s1, s2);
  941.       msgsize = 0L;
  942.       curpos = 0L;
  943.       while (1) {
  944.         if (kbhit()) {
  945.           ch = (getch());
  946.           switch (ch) {
  947.             case 27:
  948.               output("\r ■ Abort detected... please wait until message is completed [-]");
  949.               *abort = 1;
  950.               break;
  951.             case 32:
  952.               output("\r ■ Skipping group... please wait until message is completed [-]");
  953.               *abort = 2;
  954.               break;
  955.             default:
  956.               break;
  957.           }
  958.         }
  959.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  960.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  961.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  962.           break;
  963.         } else {
  964.           treat(_temp_buffer);
  965.           strcat(_temp_buffer, "\n");
  966.           curpos = strlen(_temp_buffer);
  967.           fputs(_temp_buffer, tpktfp);
  968.           msgsize += curpos;
  969.         }
  970.         if (count++ > 5) {
  971.           output("\b\b%c]", spin[place++]);
  972.           place %= len;
  973.           count = 0;
  974.         }
  975.         if ((msgsize > 30000L) && (!spooltodisk)) {
  976.           sprintf(_temp_buffer, "\nContinued in next message...\n");
  977.           fputs(_temp_buffer, tpktfp);
  978.           if (tpktfp)
  979.             fclose(tpktfp);
  980.           sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  981.           if (stat(tpktname, &statbuf) == 0)
  982.             unlink(tpktname);
  983.           if ((tpktfp = fsh_open(tpktname, "wt+")) == 0) {
  984.             log_it(0, "\n ■ Unable to create temporary packet %s", tpktname);
  985.             qexit(NNTP_sock, 1);
  986.           }
  987.           backline();
  988.           output("\r ■ Breaking into %d%s part [ ]", (
  989.                                          part - 1), ordinal_text(part - 1));
  990.           sprintf(_temp_buffer, "\nContinued from previous message...\n");
  991.           fputs(_temp_buffer, tpktfp);
  992.           msgsize = strlen(_temp_buffer);
  993.         }
  994.       }
  995.       if (tpktfp)
  996.         fclose(tpktfp);
  997.       output("\b\bX]");
  998.       return 1;
  999.     }
  1000.   }
  1001.   if (tpktfp)
  1002.     fclose(tpktfp);
  1003.   SOCK_READ_ERR(NNTP_sock);
  1004.   return 0;
  1005. }
  1006.  
  1007. int extract(char *to, char *key, char *from)
  1008. {
  1009.   if (!strnicmp(from, key, strlen(key))) {
  1010.     from += strlen(key);
  1011.     while (*from == ' ')
  1012.       from++;
  1013.     strcpy(to, from);
  1014.     return 1;
  1015.   } else
  1016.     return 0;
  1017. }
  1018.  
  1019.  
  1020. int chead(Mail_Socket * NNTP_sock)
  1021. {
  1022.   static char _temp_buffer[BIGSTR];
  1023.  
  1024.   *cur_path = 0;
  1025.   *cur_from = 0;
  1026.   *cur_replyto = 0;
  1027.   *cur_subject = 0;
  1028.   *cur_newsgroups = 0;
  1029.   *cur_message_ID = 0;
  1030.   *cur_references = 0;
  1031.   *cur_date = 0;
  1032.  
  1033.   sock_printf(NNTP_sock->sock, "HEAD %lu", cur_article);
  1034.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1035.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1036.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1037.   if (reply == 423)
  1038.     return 0;
  1039.   else
  1040.     if (reply == 221)
  1041.     while (1) {
  1042.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1043.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1044.       if (strlen(_temp_buffer) > 1024)
  1045.         _temp_buffer[1024] = 0;
  1046.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1047.         if (cur_replyto[0] == 0)
  1048.           strcpy(cur_replyto, cur_from);
  1049.         return 1;
  1050.       }
  1051.       extract(cur_path, "Path:", _temp_buffer) ||
  1052.           extract(cur_from, "From:", _temp_buffer) ||
  1053.           extract(cur_subject, "Subject:", _temp_buffer) ||
  1054.           extract(cur_replyto, "Reply-To:", _temp_buffer) ||
  1055.           extract(cur_newsgroups, "Newsgroups:", _temp_buffer) ||
  1056.           extract(cur_organization, "Organization:", _temp_buffer) ||
  1057.           extract(cur_message_ID, "Message-ID:", _temp_buffer) ||
  1058.           extract(cur_references, "References:", _temp_buffer) ||
  1059.           extract(cur_lines, "Lines:", _temp_buffer) ||
  1060.           extract(cur_date, "Date:", _temp_buffer);
  1061.     }
  1062.   else {
  1063.     log_it(0, "\n ■ Unknown chead error : %s", _temp_buffer);
  1064.   }
  1065.   SOCK_READ_ERR(NNTP_sock);
  1066.   return 0;
  1067. }
  1068.  
  1069. Mail_Socket *netsocket(char *host)
  1070. {
  1071.   Mail_Socket *NNTP_sock = NULL;
  1072.   longword h;
  1073.   static char _temp_buffer[STR];
  1074.  
  1075.   if (!(h = resolve(host)))
  1076.     err_exit(EXIT_FAILURE, "\n ■ Could not resolve %s... aborting", host);
  1077.   if ((NNTP_sock = (Mail_Socket *) farmalloc(sizeof(Mail_Socket))) == NULL)
  1078.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1079.   if ((NNTP_sock->sock = (tcp_Socket *) farmalloc(sizeof(tcp_Socket))) == NULL) {
  1080.     farfree(NNTP_sock);
  1081.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1082.   }
  1083.   if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
  1084.     free_Mail_Socket(NNTP_sock);
  1085.     err_exit(EXIT_FAILURE, "\n ■ TCP socket open failed... aborting");
  1086.   }
  1087.   sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
  1088.   sock_wait_established(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1089.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1090.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1091.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1092.   switch (reply) {
  1093.     case 200:
  1094.       log_it(0, "\n ■ Connection to %s accepted...", host);
  1095.       break;
  1096.     case 502:
  1097.       free_Mail_Socket(NNTP_sock);
  1098.       err_exit(EXIT_FAILURE, "\n ■ Connection to %s refused... try again later.", host);
  1099.       break;
  1100.     case 503:
  1101.       free_Mail_Socket(NNTP_sock);
  1102.       err_exit(EXIT_FAILURE, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
  1103.       break;
  1104.     default:
  1105.       free_Mail_Socket(NNTP_sock);
  1106.       err_exit(EXIT_FAILURE, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
  1107.       break;
  1108.   }
  1109.   SOCK_READ_ERR(NNTP_sock);
  1110.   return (NNTP_sock);
  1111. }
  1112.  
  1113. int cnext(Mail_Socket * NNTP_sock)
  1114. {
  1115.   char *p, *q;
  1116.   static char _temp_buffer[STRING];
  1117.  
  1118.   sock_printf(NNTP_sock->sock, "NEXT");
  1119.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1120.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1121.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1122.   if (reply == 421)
  1123.     return -1;
  1124.   else
  1125.     if (reply == 223) {
  1126.     cur_article = reparticle;
  1127.     p = _temp_buffer;
  1128.     q = cur_articleid;
  1129.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  1130.       p++;
  1131.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  1132.       *q++ = *p++;
  1133.     *q++ = '>';
  1134.     *q++ = '\0';
  1135.     return 0;
  1136.     }
  1137.   else {
  1138.     log_it(0, "\n ■ Unknown cnext error : %s", _temp_buffer);
  1139.   }
  1140.   SOCK_READ_ERR(NNTP_sock);
  1141.   return -1;
  1142. }
  1143.  
  1144. char *stripspace(char *str)
  1145. {
  1146.   char *obuf, *nbuf;
  1147.  
  1148.   if (str) {
  1149.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1150.       if (!isspace(*obuf))
  1151.         *nbuf++ = *obuf;
  1152.     }
  1153.     *nbuf = NULL;
  1154.   }
  1155.   return (str);
  1156. }
  1157.  
  1158.  
  1159. int sendauthinfo(Mail_Socket * NNTP_sock)
  1160. {
  1161.   char s[MAXPATH], line[121], name[21], pass[31], *ss;
  1162.   static char _temp_buffer[BIGSTR];
  1163.   FILE *fp;
  1164.  
  1165.   output("\n ■ Server requested authentication information.");
  1166.   sprintf(s, "%s\\NET.INI", maindir);
  1167.   fp = fsh_open(s, "rt");
  1168.   if (!fp) {
  1169.     output("\n ■ Unable to open %s.", s);
  1170.     return 1;
  1171.   }
  1172.   while (fgets(line, 80, fp)) {
  1173.     ss = NULL;
  1174.     stripspace(line);
  1175.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == '['))
  1176.       continue;
  1177.     if (strlen(line) == 0)
  1178.       continue;
  1179.     if (strnicmp(line, "NEWSNAME", 8) == 0) {
  1180.       ss = strtok(line, "=");
  1181.       if (ss) {
  1182.         ss = strtok(NULL, "\n");
  1183.         trimstr1(ss);
  1184.         name[0] = 0;
  1185.         strcpy(name, ss);
  1186.       }
  1187.     }
  1188.     if (strnicmp(line, "NEWSPASS", 8) == 0) {
  1189.       ss = strtok(line, "=");
  1190.       if (ss) {
  1191.         ss = strtok(NULL, "\n");
  1192.         trimstr1(ss);
  1193.         pass[0] = 0;
  1194.         strcpy(pass, ss);
  1195.       }
  1196.     }
  1197.   }
  1198.   if ((name[0] == 0) || (pass[0] == 0)) {
  1199.     output("\n ■ NEWSNAME or NEWSPASS not properly defined!");
  1200.     return 1;
  1201.   }
  1202.   while (1) {
  1203.     sprintf(_temp_buffer, "authinfo user %s", name);
  1204.     sock_printf(NNTP_sock->sock, _temp_buffer);
  1205.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1206.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1207.     sscanf(_temp_buffer, "%hu %s", &reply, s);
  1208.     if (reply == 381) {
  1209.       sprintf(_temp_buffer, "authinfo pass %s", pass);
  1210.       sock_printf(NNTP_sock->sock, _temp_buffer);
  1211.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1212.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1213.       sscanf(_temp_buffer, "%hu %s", &reply, s);
  1214.       if (reply == 281) {
  1215.         output("\n ■ Authentication accepted.  Continuing news retrieval session.");
  1216.         return 0;
  1217.       } else {
  1218.         output("\n ■ Authentication failed.  Aborting news retrieval session.");
  1219.         return 1;
  1220.       }
  1221.     } else {
  1222.       output("\n ■ Unknown response \"%hu\" from server.", reply);
  1223.       return 1;
  1224.     }
  1225.   }
  1226.   SOCK_READ_ERR(NNTP_sock);
  1227.   fclose(fp);
  1228.   return -1;
  1229. }
  1230.  
  1231. int saveactive(Mail_Socket * NNTP_sock, char *fn)
  1232. {
  1233.   char s[181], group[256], act;
  1234.   unsigned long to, from;
  1235.   int count, done;
  1236.   FILE *fp;
  1237.   static char _temp_buffer[BIGSTR];
  1238.  
  1239.   if ((fp = fsh_open(fn, "w")) == NULL) {
  1240.     perror(fn);
  1241.     return -1;
  1242.   }
  1243.   done = 0;
  1244.   while (!done) {
  1245.     sock_printf(NNTP_sock->sock, "LIST");
  1246.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1247.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1248.     sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1249.     if (reply == 215) {
  1250.       count = 0;
  1251.       while (1) {
  1252.         if (count++ % 25 == 0)
  1253.           output("\b\b\b\b\b\b\b%-7d", count);
  1254.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1255.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1256.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  1257.           break;
  1258.         sscanf(_temp_buffer, "%s %lu %lu %c", group, &to, &from, &act);
  1259.         sprintf(s, "%s %lu\n", group, to);
  1260.         fsh_write(s, sizeof(char), strlen(s), fp);
  1261.       }
  1262.       log_it(0, "\n ■ %d total newsgroups available on %s", count, serverhost);
  1263.       fclose(fp);
  1264.       return 0;
  1265.     } else {
  1266.       if (reply == 480) {
  1267.         fclose(fp);
  1268.         return 1;
  1269.       } else {
  1270.         log_it(0, "\n ■ Unknown saveactive error : %s", _temp_buffer);
  1271.         fclose(fp);
  1272.         done = 1;
  1273.       }
  1274.     }
  1275.   }
  1276.   SOCK_READ_ERR(NNTP_sock);
  1277.   return -1;
  1278. }
  1279.  
  1280. int checkx(int cug)
  1281. {
  1282.   char *ptr, *ptr2, *ptr3, buf[256];
  1283.   int i, max;
  1284.  
  1285.   ptr = strtok(cur_organization, "*");
  1286.   trimstr1(ptr);
  1287.   if (strncmpi(ptr, syscfg.systemname, strlen(syscfg.systemname)) == 0) {
  1288.     log_it(0, "\n ■ Skipping message - originally posted on %s.", syscfg.systemname);
  1289.     return 0;
  1290.   }
  1291.   ptr = cur_newsgroups;
  1292.   while (*ptr == ' ')
  1293.     ptr++;
  1294.   max = 0;
  1295.   while (1) {
  1296.     if (*ptr == 0)
  1297.       break;
  1298.     if (*ptr == ',') {
  1299.       ptr++;
  1300.       ++max;
  1301.     }
  1302.     while (*ptr == ' ')
  1303.       ptr++;
  1304.     ptr2 = ptr;
  1305.     ptr3 = buf;
  1306.     while (*ptr2 != 0 && *ptr2 != ',')
  1307.       *ptr3++ = *ptr2++;
  1308.     *ptr3 = 0;
  1309.     while (*(--ptr3) == ' ')
  1310.       *ptr3 = 0;
  1311.     ptr = ptr2;
  1312.     for (i = 0; i < cug; i++) {
  1313.       if (strcmpi(buf, grouprec[i].groupname) == 0) {
  1314.         output("\n ■ Skipping message - already posted in %s.",
  1315.                 grouprec[i].groupname);
  1316.         return 0;
  1317.       }
  1318.     }
  1319.     if ((crossposts > 0) && (max > crossposts)) {
  1320.       output("\n ■ Skipping message - crossposted to more than %hu newsgroups.",
  1321.           crossposts);
  1322.       return 0;
  1323.     }
  1324.   }
  1325.   return 1;
  1326. }
  1327.  
  1328. void good_name(char *name)
  1329. {
  1330.   char *ss;
  1331.   int i;
  1332.  
  1333.   trimstr1(name);
  1334.   if ((strcspn(name, " ") == strlen(name)) && (strcspn(name, "(") == strlen(name)))
  1335.     if (_fstrchr(name, '@') != NULL)
  1336.       return;
  1337.   if (strcspn(name, "<") != strlen(name)) {
  1338.     ss = strtok(name, "<");
  1339.     if (ss)
  1340.       ss = strtok(NULL, ">");
  1341.     strcpy(name, ss);
  1342.     if (name[0] == 0)
  1343.       strcpy(name, "Unknown");
  1344.     return;
  1345.   }
  1346.   if ((i = strcspn(name, "(")) != strlen(name)) {
  1347.     if (name[i - 1] == 32) {
  1348.       ss = strtok(name, " ");
  1349.       if (ss)
  1350.         strcpy(name, ss);
  1351.     } else {
  1352.       ss = strtok(name, "(");
  1353.       if (ss)
  1354.         strcpy(name, ss);
  1355.     }
  1356.     if (name[0] == 0)
  1357.       strcpy(name, "Unknown");
  1358.     return;
  1359.   }
  1360. }
  1361.  
  1362. int postnews(Mail_Socket * NNTP_sock, int cug)
  1363. {
  1364.   char s[181], s1[12], s2[5], fn[201], *ss;
  1365.   int f1, nlines, len, tlen;
  1366.   FILE *fp;
  1367.   static char _temp_buffer[STR];
  1368.   struct ffblk ff;
  1369.  
  1370.   sprintf(fn, "%s\\OUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
  1371.   f1 = findfirst(fn, &ff, 0);
  1372.   if (f1 != 0) {
  1373.     log_it(0, "\n ■ No outbound news articles to post...");
  1374.     return 1;
  1375.   }
  1376.   while (f1 == 0) {
  1377.     sock_printf(NNTP_sock->sock, "POST");
  1378.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1379.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1380.     if (*_temp_buffer != '3') {
  1381.       if (atoi(_temp_buffer) == 440)
  1382.         log_it(1, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
  1383.       else
  1384.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1385.       return 0;
  1386.     }
  1387.     output("\n ■ Posting article to %s\n", grouprec[cug].groupname);
  1388.     sprintf(s, "%s\\OUTBOUND\\%s", net_data, ff.ff_name);
  1389.     fp = fsh_open(s, "rb");
  1390.     nlines = 0;
  1391.     while (fgets(_temp_buffer, 120, fp) != NULL) {
  1392.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1393.         _temp_buffer[1] = '.';
  1394.         _temp_buffer[2] = 0;
  1395.       }
  1396.       tlen = 0;
  1397.       len = strlen(_temp_buffer);
  1398.       while (tlen < len) {
  1399.         if (!tcp_tick(NNTP_sock->sock)) {
  1400.           fclose(fp);
  1401.           output("\n ■ Connection reset by host");
  1402.           return 1;
  1403.         }
  1404.         tlen += sock_fastwrite(NNTP_sock->sock, &_temp_buffer[tlen], len - tlen);
  1405.       }
  1406.       backline();
  1407.       output("\r ■ Lines sent : %d", ++nlines);
  1408.     }
  1409.     fclose(fp);
  1410.     sock_printf(NNTP_sock->sock, ".\n");
  1411.     output("\n ■ Awaiting acknowledgement - may take several minutes...");
  1412.     log_it(0, "\n ■ Server response : ");
  1413.     sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
  1414.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1415.     log_it(0, "%s", _temp_buffer);
  1416.     if (*_temp_buffer != '2') {
  1417.       if (atoi(_temp_buffer) == 441) {
  1418.         ss = strtok(_temp_buffer, " ");
  1419.         ss = strtok(NULL, " ");
  1420.         if (atoi(ss) == 435)
  1421.           unlink(s);
  1422.         fnsplit(s, NULL, NULL, s1, s2);
  1423.         log_it(0, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
  1424.       } else
  1425.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1426.     } else {
  1427.       if (unlink(s) == 0)
  1428.         log_it(0, "\n ■ Deleted sent message - %s", s);
  1429.     }
  1430.     f1 = findnext(&ff);
  1431.   }
  1432.   SOCK_READ_ERR(NNTP_sock);
  1433.   return 0;
  1434. }
  1435.  
  1436. void get_subtype(int sub, char *where)
  1437. {
  1438.   int ok;
  1439.   char fn[181], s[81], net_name[21], *ss;
  1440.   FILE *fp;
  1441.  
  1442.   where[0] = 0;
  1443.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1444.   fp = fsh_open(fn, "r");
  1445.   if (!fp)
  1446.     return;
  1447.   ok = 0;
  1448.   while (fgets(s, 80, fp)) {
  1449.     if (s[0] == '!') {
  1450.       if (sub == atoi(&s[1]))
  1451.         ok = 1;
  1452.     }
  1453.     if (ok && (s[0] == '$')) {
  1454.       ss = strtok(s, " ");
  1455.       strcpy(net_name, &ss[1]);
  1456.       ss = strtok(NULL, " ");
  1457.       fclose(fp);
  1458.       if ((stricmp(net_name, "FILENET") == 0)) {
  1459.         trimstr1(ss);
  1460.         strcpy(where, ss);
  1461.         return;
  1462.       } else
  1463.         return;
  1464.     }
  1465.   }
  1466.   fclose(fp);
  1467. }
  1468.  
  1469. unsigned int max_on_sub(int cug)
  1470. {
  1471.   int i, sub, f, max_subs, num_subs;
  1472.   char s[121], subtype[12];
  1473.   unsigned int max;
  1474.  
  1475.   if ((strlen(grouprec[cug].subtype) == 1) &&
  1476.       (grouprec[cug].subtype[0] == '0'))
  1477.     return 0;
  1478.   max_subs = syscfg.max_subs;
  1479.   subboards = (subboardrec *) mallocx(max_subs * sizeof(subboardrec));
  1480.   if (!subboards) {
  1481.     output("\b\b\b\bUnable to allocate %ld bytes.",
  1482.             max_subs * sizeof(subboardrec));
  1483.     return 0;
  1484.   }
  1485.   sprintf(s, "%sSUBS.DAT", syscfg.datadir);
  1486.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1487.   if (f < 0) {
  1488.     output("\n ■ %s NOT FOUND", s);
  1489.     return 0;
  1490.   }
  1491.   num_subs = (sh_read(f, subboards, (max_subs * sizeof(subboardrec)))) /
  1492.       sizeof(subboardrec);
  1493.   f = sh_close(f);
  1494.   for (i = 0; i < num_subs; i++) {
  1495.     sub = i;
  1496.     output("\b\b\b\b%-4d", sub);
  1497.     get_subtype(sub, subtype);
  1498.     if (stricmp(subtype, grouprec[cug].subtype) == 0) {
  1499.       max = subboards[i].maxmsgs;
  1500.       output("\b\b\b\b%s - %hu posts.", subtype, max);
  1501.       if (subboards)
  1502.         free(subboards);
  1503.       return max;
  1504.     }
  1505.   }
  1506.   if (subboards)
  1507.     free(subboards);
  1508.   return 0;
  1509. }
  1510.  
  1511. int getnews(char *hostname)
  1512. {
  1513.   int f1, nup, nug, cug, abort, ok, done, firstrun, max_articles, parts;
  1514.   char *p, fn[201], mailname[121], reline[121], s[21], s1[21], pktname[121];
  1515.   char orig_subj[STRING];
  1516.   unsigned int text_len;
  1517.   unsigned short temptype;
  1518.   unsigned long new_articles;
  1519.   net_header_rec nh;
  1520.   struct date dt;
  1521.   struct time tm;
  1522.   struct ffblk ff;
  1523.   static FILE *fp;
  1524.   Mail_Socket *nntp_sock;
  1525.   static char _temp_buffer[STR];
  1526.  
  1527.   abort = cug = 0;
  1528.   sock_init();
  1529.   nntp_sock = netsocket(hostname);
  1530.  
  1531.   if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
  1532.     grouprec[0].groupname[0] = 0;
  1533.     write_groups(0);
  1534.     if (grouprec)
  1535.       free(grouprec);
  1536.     sprintf(fn, "%s\\NEWSRC", net_data);
  1537.     log_it(0, "\n ■ Creating newsgroup list : %s...         ", fn);
  1538.     if (saveactive(nntp_sock, fn) == 1) {
  1539.       if (sendauthinfo(nntp_sock) == 0)
  1540.         saveactive(nntp_sock, fn);
  1541.     }
  1542.     nntp_shutdown(nntp_sock);
  1543.     free_Mail_Socket(nntp_sock);
  1544.     return 0;
  1545.   }
  1546.   nug = nup = 1;
  1547.   while ((cug < ngroups) && (!abort)) {
  1548.     if (nup) {
  1549.       nup = 0;
  1550.       if (grouprec[cug].subtype) {
  1551.         if (fp)
  1552.           fclose(fp);
  1553.         write_groups(0);
  1554.         name_packet(pktname);
  1555.         if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1556.           log_it(0, "\n ■ Unable to create %s!", pktname);
  1557.           qexit(nntp_sock, 1);
  1558.         } else {
  1559.           fnsplit(pktname, NULL, NULL, s, s1);
  1560.           output("\n ■ Creating new packet : %s%s", s, s1);
  1561.         }
  1562.       } else {
  1563.         if (fp) {
  1564.           fclose(fp);
  1565.         }
  1566.       }
  1567.     }
  1568.     if (nug) {
  1569.       cur_article = ++grouprec[cug].lastread;
  1570.       nug = 0;
  1571.       while (1) {
  1572.         if (cgroup(nntp_sock, grouprec[cug].groupname)) {
  1573.           if (cgroup(nntp_sock, grouprec[cug].groupname) == 2) {
  1574.             if (sendauthinfo(nntp_sock) == 0)
  1575.               continue;
  1576.             else
  1577.               return 1;
  1578.           }
  1579.           log_it(1, "\n ■ Error accessing newsgroup \"%s\".",
  1580.                  grouprec[cug].groupname);
  1581.           if (++bogus >= 10) {
  1582.             log_it(0, "\n ■ More than 10 invalid newsgroups... possible NEWS.RC error!");
  1583.             qexit(nntp_sock, 10);
  1584.           }
  1585.           nug = 1;
  1586.           break;
  1587.         } else
  1588.           break;
  1589.       }
  1590.       if (!nug) {
  1591.         log_it(0, "\n ■ Requesting %s... ", grouprec[cug].groupname);
  1592.         if (grouprec[cug].lastread < cur_first)
  1593.           grouprec[cug].lastread = cur_first;
  1594.         if (grouprec[cug].lastread > cur_last) {
  1595.           grouprec[cug].lastread = cur_last;
  1596.           log_it(0, "no new articles.");
  1597.           nug = 1;
  1598.         } else {
  1599.           new_articles = cur_last - grouprec[cug].lastread + 1;
  1600.           log_it(0, "%lu new article%s.        ",
  1601.                  cur_last - grouprec[cug].lastread + 1,
  1602.                  new_articles == 1 ? "" : "s");
  1603.           if (new_articles > 250) {
  1604.             output("\n ■ Maximum posts allowed on subtype     ");
  1605.             max_articles = max_on_sub(cug);
  1606.             if (max_articles && (new_articles > max_articles)) {
  1607.               log_it(0, "\n ■ Requesting most recent %d articles", max_articles);
  1608.               grouprec[cug].lastread = (cur_last - max_articles);
  1609.             }
  1610.           }
  1611.         }
  1612.         postnews(nntp_sock, cug);
  1613.         if (!nug) {
  1614.           if (cur_numa == 0) {
  1615.             log_it(0, "\n ■ No articles available in %s...",
  1616.                    grouprec[cug].groupname);
  1617.             nug = 1;
  1618.             continue;
  1619.           } else {
  1620.             if (cstat(nntp_sock, grouprec[cug].lastread) &&
  1621.                 cstat(nntp_sock, cur_last))
  1622.               nug = 1;
  1623.           }
  1624.         }
  1625.       }
  1626.     } else {
  1627.       if (cnext(nntp_sock)) {
  1628.         output("\n ■ End of new articles in %s",
  1629.                 grouprec[cug].groupname);
  1630.         nug = 1;
  1631.         write_groups(1);
  1632.       }
  1633.     }
  1634.     if (kbhit()) {
  1635.       if (getch() == 27) {
  1636.         log_it(0,"\n ■ Aborting news retrieval session...");
  1637.         if (fp)
  1638.           fclose(fp);
  1639.         nntp_shutdown(nntp_sock);
  1640.         free_Mail_Socket(nntp_sock);
  1641.         return 1;
  1642.       }
  1643.     }
  1644.     if (!nug) {
  1645.       if ((chead(nntp_sock)) && (checkx(cug))) {
  1646.         if (cur_subject[0]) {
  1647.           treat(cur_subject);
  1648.           if (strlen(cur_subject) > 65)
  1649.             cur_subject[65] = '\0';
  1650.         } else
  1651.           strcpy(cur_subject, "No subject");
  1652.         strcpy(orig_subj, cur_subject);
  1653.         if (cur_from[0]) {
  1654.           treat(cur_from);
  1655.           if (strlen(cur_from) > 45)
  1656.             cur_from[45] = 0;
  1657.         } else
  1658.           strcpy(cur_from, "Unknown");
  1659.         if (cur_replyto[0]) {
  1660.           if (strlen(cur_replyto) > 45)
  1661.             cur_replyto[45] = 0;
  1662.         }
  1663.         strncpy(_temp_buffer, orig_subj, 55);
  1664.         _temp_buffer[55] = '\0';
  1665.         output("\n ■ [%lu/%lu] : %s ", cur_article,
  1666.                 cur_last, _temp_buffer);
  1667.         ok = savebody(nntp_sock, cug, &abort);
  1668.         if (ok && grouprec[cug].subtype) {
  1669.           strcpy(msgarea, grouprec[cug].groupname);
  1670.           sprintf(msgto, "All");
  1671.           sprintf(fn, "%s\\INPUT*.MSG", tmpdir);
  1672.           done = 1;
  1673.           parts = 0;
  1674.           if (findfirst(fn, &ff, 0) == 0) {
  1675.             parts = 1;
  1676.             done = 0;
  1677.           }
  1678.           firstrun = 1;
  1679.           while (!done) {
  1680.             sprintf(fn, "%s\\%s", tmpdir, ff.ff_name);
  1681.             f1 = sh_open1(fn, O_RDONLY | O_BINARY);
  1682.             text_len = (unsigned int) filelength(f1);
  1683.             if (text_len > 32000L) {
  1684.               output("\n ■ Truncating %lu bytes from input file",
  1685.                       text_len - 32000L);
  1686.               text_len = 32000;
  1687.             }
  1688.             p = (char *) malloca(32767);
  1689.             if (!p) {
  1690.               log_it(0, "\n ■ Insufficient memory to read entire message");
  1691.               qexit(nntp_sock, 1);
  1692.             }
  1693.             sh_read(f1, (void *) p, text_len);
  1694.             sh_close(f1);
  1695.             temptype = atoi(grouprec[cug].subtype);
  1696.             nh.tosys = sy;
  1697.             nh.touser = 0;
  1698.             nh.fromsys = 32767;
  1699.             nh.fromuser = 0;
  1700.             if (!temptype) {
  1701.               nh.main_type = main_type_new_post;
  1702.               nh.minor_type = 0;
  1703.             } else {
  1704.               nh.main_type = main_type_pre_post;
  1705.               nh.minor_type = temptype;
  1706.             }
  1707.             nh.list_len = 0;
  1708.             gettime(&tm);
  1709.             getdate(&dt);
  1710.             nh.daten = dostounix(&dt, &tm);
  1711.             nh.method = 0;
  1712.             if (parts > 1) {
  1713.               sprintf(_temp_buffer, "%d%s ", parts, ordinal_text(parts));
  1714.               strcat(_temp_buffer, orig_subj);
  1715.               strcpy(cur_subject, _temp_buffer);
  1716.               if (strlen(cur_subject) > 72)
  1717.                 cur_subject[72] = '\0';
  1718.               else
  1719.                 cur_subject[strlen(cur_subject)] = '\0';
  1720.             }
  1721.             nh.length = text_len + strlen(cur_subject) + 1;
  1722.             strncpy(mailname, cur_replyto, 46);
  1723.             strcat(mailname, "\r\n");
  1724.             nh.length += strlen(mailname);
  1725.             nh.length += 24 + 2;
  1726.             if (nh.main_type == main_type_new_post)
  1727.               nh.length += strlen(grouprec[cug].subtype) + 1;
  1728.             if (firstrun) {
  1729.               firstrun = 0;
  1730.               if (strncmpi(cur_articleid, "re: ", 4) == 0) {
  1731.                 strncpy(reline, cur_articleid, 60);
  1732.                 sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
  1733.               }
  1734.             }
  1735.             nh.length += strlen(cur_articleid);
  1736.             fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1737.             if (nh.main_type == main_type_new_post)
  1738.               fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
  1739.             fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
  1740.             fsh_write(mailname, sizeof(char), strlen(mailname), fp);
  1741.             strncpy(_temp_buffer, ctime(&(time_t) nh.daten), 24);
  1742.             _temp_buffer[24] = '\0';
  1743.             strcat(_temp_buffer, "\r\n");
  1744.             fsh_write(_temp_buffer, sizeof(char), strlen(_temp_buffer), fp);
  1745.             sprintf(_temp_buffer, "%s\n\n", cur_articleid);
  1746.             fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
  1747.             fsh_write(p, sizeof(char), text_len, fp);
  1748.             if (p)
  1749.               free(p);
  1750.             unlink(fn);
  1751.             if (findnext(&ff) == 0) {
  1752.               done = 0;
  1753.               ++parts;
  1754.             } else
  1755.               done = 1;
  1756.           }
  1757.         }
  1758.         grouprec[cug].lastread = cur_article;
  1759.       } else
  1760.         grouprec[cug].lastread = cur_article + 1;
  1761.       if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
  1762.         nup = 1;
  1763.       if (abort == 2) {
  1764.         write_groups(1);
  1765.         nug = 1;
  1766.         abort = 0;
  1767.       }
  1768.     }
  1769.     if (nug) {
  1770.       ++cug;
  1771.       if (((strlen(grouprec[cug].subtype) == 1) &&
  1772.            (grouprec[cug].subtype[0] == '0')) && (grouprec[cug].subtype)) {
  1773.         nup = 1;
  1774.       } else {
  1775.         if ((grouprec[cug - 1].subtype) &&
  1776.             ((strlen(grouprec[cug].subtype) == 1) &&
  1777.              (grouprec[cug].subtype[0] == '0'))) {
  1778.           if (fp) {
  1779.             fclose(fp);
  1780.           }
  1781.         }
  1782.       }
  1783.     }
  1784.   }
  1785.   if (fp)
  1786.     fclose(fp);
  1787.   if (abort)
  1788.     log_it(0, "\n ■ Session aborted from keyboard");
  1789.   write_groups(1);
  1790.   nntp_shutdown(nntp_sock);
  1791.   free_Mail_Socket(nntp_sock);
  1792.   return 0;
  1793. }
  1794.  
  1795. void main(int argc, char *argv[])
  1796. {
  1797.   int f, done;
  1798.   char s[201], fn[MAXPATH], *ss;
  1799.   FILE *fp;
  1800.   struct tm *time_now;
  1801.   time_t some;
  1802.  
  1803.   cursor('S');
  1804.   cursor('H');
  1805.   output("\n ■ %s", version);
  1806.   if (argc != 4)
  1807.     err_exit(EXIT_FAILURE, "\n ■ Invalid arguments for %s", argv[0]);
  1808.   ss = getenv("WWIV_INSTANCE");
  1809.   if (ss) {
  1810.     instance = atoi(ss);
  1811.     if ((instance <= 0) || (instance >= 1000)) {
  1812.       log_it(0, "\n ■ WWIV_INSTANCE set to %d.  Can only be 1..999!", instance);
  1813.       instance = 1;
  1814.     }
  1815.   } else
  1816.     instance = 1;
  1817.   SOCK_DELAY = 120;
  1818.   get_dir(maindir, 0);
  1819.   strcpy(net_data, argv[1]);
  1820.   strcpy(serverhost, argv[2]);
  1821.   detect_multitask();
  1822.   time(&some);
  1823.   time_now = localtime(&some);
  1824.   strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1825.            time_now);
  1826.   sprintf(fn, "%s\\NEWS.LOG", net_data);
  1827.   if ((fp = fsh_open(fn, "at")) != NULL) {
  1828.     fprintf(fp, s);
  1829.     fclose(fp);
  1830.   }
  1831.   sprintf(tmpdir, "%s\\SPOOL", net_data);
  1832.   sy = atoi(argv[3]);
  1833.   sprintf(s, "%s\\CONFIG.DAT", maindir);
  1834.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1835.   if (f < 0)
  1836.     err_exit(EXIT_FAILURE, "\n ■ %s NOT FOUND.", s);
  1837.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1838.   sh_close(f);
  1839.   sprintf(newsrc, "%s\\NEWS.RC", net_data);
  1840.   read_groups();
  1841.   if (ngroups == 0)
  1842.     err_exit(EXIT_FAILURE, "\n ■ Unable to access newsgroup file: %s!", newsrc);
  1843.   if (stricmp(grouprec[0].groupname, "newsrc") == 0)
  1844.     log_it(0, "\n ■ Retrieving current newsgroup listing from %s",
  1845.            serverhost);
  1846.   else
  1847.     log_it(0, "\n ■ %u newsgroup%s defined in %s", ngroups,
  1848.            ngroups == 1 ? "" : "s", strlwr(newsrc));
  1849.   crossposts = 10;
  1850.   sprintf(fn, "%s\\NET.INI", maindir);
  1851.   fp = fsh_open(fn, "rt");
  1852.   if (!fp)
  1853.     output("\n ■ Unable to read %s", fn);
  1854.   else {
  1855.     done = 0;
  1856.     while ((fgets(s, 80, fp)) && (!done)) {
  1857.       ss = NULL;
  1858.       stripspace(s);
  1859.       if ((s[0] == ';') || (s[0] == '\n') || (s[0]== '['))
  1860.         continue;
  1861.       if (strlen(s) == 0)
  1862.         continue;
  1863.       if (strnicmp(s, "XPOSTS", 6) == 0) {
  1864.         ss = strtok(s, "=");
  1865.         if (ss) {
  1866.           ss = strtok(NULL, "\n");
  1867.           trimstr1(ss);
  1868.           crossposts = atoi(ss);
  1869.           if (crossposts > 99)
  1870.             crossposts = 10;
  1871.           done = 1;
  1872.         }
  1873.       }
  1874.     }
  1875.   }
  1876.   if (getnews(serverhost))
  1877.     err_exit(EXIT_FAILURE, "\n ■ Exiting program.");
  1878.   if (grouprec)
  1879.     free(grouprec);
  1880.   grouprec = NULL;
  1881.   cd_to(maindir);
  1882.   log_it(0, "\n ■ NEWS succesfully completed processing %d newsgroups", ngroups);
  1883.   trim_log();
  1884.   err_exit(EXIT_SUCCESS, "\n ■ Normal program termination");
  1885. }
  1886.