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