home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B25.ZIP / NEWS.C < prev    next >
C/C++ Source or Header  |  1997-04-28  |  51KB  |  1,864 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, 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)) {
  802.         *nbuf++ = *obuf;
  803.       }
  804.     }
  805.   }
  806. }
  807.  
  808. void name_packet(char *pktname)
  809. {
  810.   int ok;
  811.   struct stat info;
  812.   unsigned i;
  813.  
  814.   ok = 0;
  815.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  816.     sprintf(pktname, "%s\\P0-%u.%3.3d", net_data, i, instance);
  817.     if (stat(pktname, &info) == -1)
  818.       ok = 1;
  819.   }
  820. }
  821.  
  822. int savebody(Mail_Socket * NNTP_sock, int cug, int *abort)
  823. {
  824.   char s1[21], s2[21], ch;
  825.   unsigned int curpos, count, part;
  826.   char spin[26];
  827.   int i, place, len, spooltodisk;
  828.   unsigned long msgsize;
  829.   struct stat statbuf;
  830.   FILE *tpktfp = NULL;
  831.   static char _temp_buffer[BIGSTR];
  832.  
  833.   strcpy(spin, "||//--\\\\");
  834.   place = count = spooltodisk = 0;
  835.   len = strlen(spin);
  836.  
  837.   if ((strlen(grouprec[cug].subtype) == 1) &&
  838.       (grouprec[cug].subtype[0] == '0'))
  839.     spooltodisk = 1;
  840.   part = 1;
  841.   if (spooltodisk)
  842.     sprintf(tpktname, "%s\\NEWS%d.UUE", tmpdir, cug);
  843.   else {
  844.     sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  845.     if (stat(tpktname, &statbuf) == 0)
  846.       unlink(tpktname);
  847.   }
  848.   sock_printf(NNTP_sock->sock, "BODY %lu", cur_article);
  849.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  850.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  851.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  852.   if (reply == 423)
  853.     return -1;
  854.   else {
  855.     if (reply == 222) {
  856.       if (grouprec[cug].subtype) {
  857.         if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
  858.           log_it("\n ■ Unable to create temporary packet %s", tpktname);
  859.           qexit(NNTP_sock, 1);
  860.         }
  861.       } else {
  862.         if (tpktfp)
  863.           fclose(tpktfp);
  864.         if ((tpktfp = fsh_open(tpktname, "at+")) == NULL) {
  865.           log_it("\n ■ Unable to create temporary packet %s", tpktname);
  866.           qexit(NNTP_sock, 1);
  867.         } else {
  868.           fputs("\n", tpktfp);
  869.           for (i = 0; i < 79; i++)
  870.             fputs("-", tpktfp);
  871.           fputs("\n", tpktfp);
  872.           sprintf(_temp_buffer, "Art  : %lu\n", cur_article);
  873.           fputs(_temp_buffer, tpktfp);
  874.           sprintf(_temp_buffer, "Date : %s\n", cur_date);
  875.           fputs(_temp_buffer, tpktfp);
  876.           sprintf(_temp_buffer, "From : %s\n", cur_replyto);
  877.           fputs(_temp_buffer, tpktfp);
  878.           sprintf(_temp_buffer, "Subj : %s\n\n", cur_subject);
  879.           fputs(_temp_buffer, tpktfp);
  880.         }
  881.       }
  882.       fnsplit(tpktname, NULL, NULL, s1, s2);
  883.       if (!spooltodisk)
  884.         fprintf(stderr, "\n ■ Receiving message - <Esc> aborts - <Space> skips group [-]");
  885.       else
  886.         fprintf(stderr, "\n ■ Appending to %s%s - <Esc> aborts - <Space> skips group [-]", s1, s2);
  887.       msgsize = 0L;
  888.       curpos = 0L;
  889.       while (1) {
  890.         if (kbhit()) {
  891.           ch = (getch());
  892.           switch (ch) {
  893.             case 27:
  894.               fprintf(stderr, "\r ■ Abort detected... please wait until message is completed [-]");
  895.               *abort = 1;
  896.               break;
  897.             case 32:
  898.               fprintf(stderr, "\r ■ Skipping group... please wait until message is completed [-]");
  899.               *abort = 2;
  900.               break;
  901.             default:
  902.               break;
  903.           }
  904.         }
  905.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  906.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  907.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  908.           break;
  909.         } else {
  910.           treat(_temp_buffer);
  911.           strcat(_temp_buffer, "\n");
  912.           curpos = strlen(_temp_buffer);
  913.           fputs(_temp_buffer, tpktfp);
  914.           msgsize += curpos;
  915.         }
  916.         if (count++ > 5) {
  917.           fprintf(stderr, "\b\b%c]", spin[place++]);
  918.           place %= len;
  919.           count = 0;
  920.         }
  921.         if ((msgsize > 30000L) && (!spooltodisk)) {
  922.           sprintf(_temp_buffer, "\nContinued in next message...\n");
  923.           fputs(_temp_buffer, tpktfp);
  924.           if (tpktfp)
  925.             fclose(tpktfp);
  926.           sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  927.           if (stat(tpktname, &statbuf) == 0)
  928.             unlink(tpktname);
  929.           if ((tpktfp = fsh_open(tpktname, "wt+")) == 0) {
  930.             log_it("\n ■ Unable to create temporary packet %s", tpktname);
  931.             qexit(NNTP_sock, 1);
  932.           }
  933.           backline();
  934.           fprintf(stderr, "\r ■ Breaking into %d%s part [ ]", (
  935.                                          part - 1), ordinal_text(part - 1));
  936.           sprintf(_temp_buffer, "\nContinued from previous message...\n");
  937.           fputs(_temp_buffer, tpktfp);
  938.           msgsize = strlen(_temp_buffer);
  939.         }
  940.       }
  941.       if (tpktfp)
  942.         fclose(tpktfp);
  943.       fprintf(stderr, "\b\bX]");
  944.       return 1;
  945.     }
  946.   }
  947.   if (tpktfp)
  948.     fclose(tpktfp);
  949.   SOCK_READ_ERR(NNTP_sock);
  950.   return 0;
  951. }
  952.  
  953. int extract(char *to, char *key, char *from)
  954. {
  955.   if (!strnicmp(from, key, strlen(key))) {
  956.     from += strlen(key);
  957.     while (*from == ' ')
  958.       from++;
  959.     strcpy(to, from);
  960.     return 1;
  961.   } else
  962.     return 0;
  963. }
  964.  
  965.  
  966. int chead(Mail_Socket * NNTP_sock)
  967. {
  968.   static char _temp_buffer[BIGSTR];
  969.  
  970.   *cur_path = 0;
  971.   *cur_from = 0;
  972.   *cur_replyto = 0;
  973.   *cur_subject = 0;
  974.   *cur_newsgroups = 0;
  975.   *cur_message_ID = 0;
  976.   *cur_references = 0;
  977.   *cur_date = 0;
  978.  
  979.   sock_printf(NNTP_sock->sock, "HEAD %lu", cur_article);
  980.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  981.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  982.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  983.   if (reply == 423)
  984.     return 0;
  985.   else
  986.     if (reply == 221)
  987.     while (1) {
  988.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  989.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  990.       if (strlen(_temp_buffer) > 1024)
  991.         _temp_buffer[1024] = 0;
  992.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  993.         if (cur_replyto[0] == 0)
  994.           strcpy(cur_replyto, cur_from);
  995.         return 1;
  996.       }
  997.       extract(cur_path, "Path:", _temp_buffer) ||
  998.           extract(cur_from, "From:", _temp_buffer) ||
  999.           extract(cur_subject, "Subject:", _temp_buffer) ||
  1000.           extract(cur_replyto, "Reply-To:", _temp_buffer) ||
  1001.           extract(cur_newsgroups, "Newsgroups:", _temp_buffer) ||
  1002.           extract(cur_organization, "Organization:", _temp_buffer) ||
  1003.           extract(cur_message_ID, "Message-ID:", _temp_buffer) ||
  1004.           extract(cur_references, "References:", _temp_buffer) ||
  1005.           extract(cur_lines, "Lines:", _temp_buffer) ||
  1006.           extract(cur_date, "Date:", _temp_buffer);
  1007.     }
  1008.   else {
  1009.     log_it("\n ■ Unknown chead error : %s", _temp_buffer);
  1010.   }
  1011.   SOCK_READ_ERR(NNTP_sock);
  1012.   return 0;
  1013. }
  1014.  
  1015. Mail_Socket *netsocket(char *host)
  1016. {
  1017.   Mail_Socket *NNTP_sock = NULL;
  1018.   longword h;
  1019.   static char _temp_buffer[STR];
  1020.  
  1021.   if (!(h = resolve(host)))
  1022.     err_exit(EXIT_FAILURE, "\n ■ Could not resolve %s... aborting", host);
  1023.   if ((NNTP_sock = (Mail_Socket *) farmalloc(sizeof(Mail_Socket))) == NULL)
  1024.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1025.   if ((NNTP_sock->sock = (tcp_Socket *) farmalloc(sizeof(tcp_Socket))) == NULL) {
  1026.     farfree(NNTP_sock);
  1027.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1028.   }
  1029.   if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
  1030.     free_Mail_Socket(NNTP_sock);
  1031.     err_exit(EXIT_FAILURE, "\n ■ TCP socket open failed... aborting");
  1032.   }
  1033.   sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
  1034.   sock_wait_established(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1035.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1036.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1037.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1038.   switch (reply) {
  1039.     case 200:
  1040.       log_it("\n ■ Connection to %s accepted...", host);
  1041.       break;
  1042.     case 502:
  1043.       free_Mail_Socket(NNTP_sock);
  1044.       err_exit(EXIT_FAILURE, "\n ■ Connection to %s refused... try again later.", host);
  1045.       break;
  1046.     case 503:
  1047.       free_Mail_Socket(NNTP_sock);
  1048.       err_exit(EXIT_FAILURE, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
  1049.       break;
  1050.     default:
  1051.       free_Mail_Socket(NNTP_sock);
  1052.       err_exit(EXIT_FAILURE, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
  1053.       break;
  1054.   }
  1055.   SOCK_READ_ERR(NNTP_sock);
  1056.   return (NNTP_sock);
  1057. }
  1058.  
  1059. int cnext(Mail_Socket * NNTP_sock)
  1060. {
  1061.   char *p, *q;
  1062.   static char _temp_buffer[STRING];
  1063.  
  1064.   sock_printf(NNTP_sock->sock, "NEXT");
  1065.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1066.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1067.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1068.   if (reply == 421)
  1069.     return -1;
  1070.   else
  1071.     if (reply == 223) {
  1072.     cur_article = reparticle;
  1073.     p = _temp_buffer;
  1074.     q = cur_articleid;
  1075.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  1076.       p++;
  1077.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  1078.       *q++ = *p++;
  1079.     *q++ = '>';
  1080.     *q++ = '\0';
  1081.     return 0;
  1082.     }
  1083.   else {
  1084.     log_it("\n ■ Unknown cnext error : %s", _temp_buffer);
  1085.   }
  1086.   SOCK_READ_ERR(NNTP_sock);
  1087.   return -1;
  1088. }
  1089.  
  1090. char *stripspace(char *str)
  1091. {
  1092.   char *obuf, *nbuf;
  1093.  
  1094.   if (str) {
  1095.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1096.       if (!isspace(*obuf))
  1097.         *nbuf++ = *obuf;
  1098.     }
  1099.     *nbuf = NULL;
  1100.   }
  1101.   return (str);
  1102. }
  1103.  
  1104.  
  1105. int sendauthinfo(Mail_Socket * NNTP_sock)
  1106. {
  1107.   char s[MAXPATH], line[121], name[21], pass[31], *ss;
  1108.   static char _temp_buffer[BIGSTR];
  1109.   FILE *fp;
  1110.  
  1111.   fprintf(stderr, "\n ■ Server requested authentication information.");
  1112.   sprintf(s, "%s\\NET.INI", maindir);
  1113.   fp = fsh_open(s, "rt");
  1114.   if (!fp) {
  1115.     fprintf(stderr, "\n ■ Unable to open %s.", s);
  1116.     return 1;
  1117.   }
  1118.   while (fgets(line, 80, fp)) {
  1119.     ss = NULL;
  1120.     stripspace(line);
  1121.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == '['))
  1122.       continue;
  1123.     if (strlen(line) == 0)
  1124.       continue;
  1125.     if (strnicmp(line, "NEWSNAME", 8) == 0) {
  1126.       ss = strtok(line, "=");
  1127.       if (ss) {
  1128.         ss = strtok(NULL, "\n");
  1129.         trimstr1(ss);
  1130.         name[0] = 0;
  1131.         strcpy(name, ss);
  1132.       }
  1133.     }
  1134.     if (strnicmp(line, "NEWSPASS", 8) == 0) {
  1135.       ss = strtok(line, "=");
  1136.       if (ss) {
  1137.         ss = strtok(NULL, "\n");
  1138.         trimstr1(ss);
  1139.         pass[0] = 0;
  1140.         strcpy(pass, ss);
  1141.       }
  1142.     }
  1143.   }
  1144.   if ((name[0] == 0) || (pass[0] == 0)) {
  1145.     fprintf(stderr, "\n ■ NEWSNAME or NEWSPASS not properly defined!");
  1146.     return 1;
  1147.   }
  1148.   while (1) {
  1149.     sprintf(_temp_buffer, "authinfo user %s", name);
  1150.     sock_printf(NNTP_sock->sock, _temp_buffer);
  1151.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1152.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1153.     sscanf(_temp_buffer, "%hu %s", &reply, s);
  1154.     if (reply == 381) {
  1155.       sprintf(_temp_buffer, "authinfo pass %s", pass);
  1156.       sock_printf(NNTP_sock->sock, _temp_buffer);
  1157.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1158.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1159.       sscanf(_temp_buffer, "%hu %s", &reply, s);
  1160.       if (reply == 281) {
  1161.         fprintf(stderr, "\n ■ Authentication accepted.  Continuing news retrieval session.");
  1162.         return 0;
  1163.       } else {
  1164.         fprintf(stderr, "\n ■ Authentication failed.  Aborting news retrieval session.");
  1165.         return 1;
  1166.       }
  1167.     } else {
  1168.       fprintf(stderr, "\n ■ Unknown response \"%hu\" from server.", reply);
  1169.       return 1;
  1170.     }
  1171.   }
  1172.   SOCK_READ_ERR(NNTP_sock);
  1173.   fclose(fp);
  1174.   return -1;
  1175. }
  1176.  
  1177. int saveactive(Mail_Socket * NNTP_sock, char *fn)
  1178. {
  1179.   char s[181], group[256], act;
  1180.   unsigned long to, from;
  1181.   int count, done;
  1182.   FILE *fp;
  1183.   static char _temp_buffer[BIGSTR];
  1184.  
  1185.   if ((fp = fsh_open(fn, "w")) == NULL) {
  1186.     perror(fn);
  1187.     return -1;
  1188.   }
  1189.   done = 0;
  1190.   while (!done) {
  1191.     sock_printf(NNTP_sock->sock, "LIST");
  1192.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1193.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1194.     sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1195.     if (reply == 215) {
  1196.       count = 0;
  1197.       while (1) {
  1198.         if (count++ % 25 == 0)
  1199.           fprintf(stderr, "\b\b\b\b\b\b\b%-7d", count);
  1200.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1201.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1202.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  1203.           break;
  1204.         sscanf(_temp_buffer, "%s %lu %lu %c", group, &to, &from, &act);
  1205.         sprintf(s, "%s %lu\n", group, to);
  1206.         fsh_write(s, sizeof(char), strlen(s), fp);
  1207.       }
  1208.       log_it("\n ■ %d total newsgroups available on %s", count, serverhost);
  1209.       fclose(fp);
  1210.       return 0;
  1211.     } else {
  1212.       if (reply == 480) {
  1213.         fclose(fp);
  1214.         return 1;
  1215.       } else {
  1216.         log_it("\n ■ Unknown saveactive error : %s", _temp_buffer);
  1217.         fclose(fp);
  1218.         done = 1;
  1219.       }
  1220.     }
  1221.   }
  1222.   SOCK_READ_ERR(NNTP_sock);
  1223.   return -1;
  1224. }
  1225.  
  1226. int checkx(int cug)
  1227. {
  1228.   char *ptr, *ptr2, *ptr3, buf[256];
  1229.   int i, max;
  1230.  
  1231.   if (cug == 0)
  1232.     return 1;
  1233.   ptr = strtok(cur_organization, "*");
  1234.   trimstr1(ptr);
  1235.   if (strcmpi(ptr, syscfg.systemname) == 0) {
  1236.     log_it("\n ■ Skipping message - originally posted on %s.", syscfg.systemname);
  1237.     return 0;
  1238.   }
  1239.   ptr = cur_newsgroups;
  1240.   while (*ptr == ' ')
  1241.     ptr++;
  1242.   max = 0;
  1243.   while (1) {
  1244.     if (*ptr == 0)
  1245.       break;
  1246.     if (*ptr == ',') {
  1247.       ptr++;
  1248.       ++max;
  1249.     }
  1250.     while (*ptr == ' ')
  1251.       ptr++;
  1252.     ptr2 = ptr;
  1253.     ptr3 = buf;
  1254.     while (*ptr2 != 0 && *ptr2 != ',')
  1255.       *ptr3++ = *ptr2++;
  1256.     *ptr3 = 0;
  1257.     while (*(--ptr3) == ' ')
  1258.       *ptr3 = 0;
  1259.     ptr = ptr2;
  1260.     for (i = 0; i < cug; i++) {
  1261.       if (strcmpi(buf, grouprec[i].groupname) == 0) {
  1262.         fprintf(stderr, "\n ■ Skipping message - already posted in %s.",
  1263.                 grouprec[i].groupname);
  1264.         return 0;
  1265.       }
  1266.     }
  1267.     if (max > crossposts) {
  1268.       fprintf(stderr, "\n ■ Skipping message - crossposted to more than %hu newsgroups.",
  1269.           crossposts);
  1270.       return 0;
  1271.     }
  1272.   }
  1273.   return 1;
  1274. }
  1275.  
  1276. void good_name(char *name)
  1277. {
  1278.   char *ss;
  1279.   int i;
  1280.  
  1281.   trimstr1(name);
  1282.   if ((strcspn(name, " ") == strlen(name)) && (strcspn(name, "(") == strlen(name)))
  1283.     if (_fstrchr(name, '@') != NULL)
  1284.       return;
  1285.   if (strcspn(name, "<") != strlen(name)) {
  1286.     ss = strtok(name, "<");
  1287.     if (ss)
  1288.       ss = strtok(NULL, ">");
  1289.     strcpy(name, ss);
  1290.     if (name[0] == 0)
  1291.       strcpy(name, "Unknown");
  1292.     return;
  1293.   }
  1294.   if ((i = strcspn(name, "(")) != strlen(name)) {
  1295.     if (name[i - 1] == 32) {
  1296.       ss = strtok(name, " ");
  1297.       if (ss)
  1298.         strcpy(name, ss);
  1299.     } else {
  1300.       ss = strtok(name, "(");
  1301.       if (ss)
  1302.         strcpy(name, ss);
  1303.     }
  1304.     if (name[0] == 0)
  1305.       strcpy(name, "Unknown");
  1306.     return;
  1307.   }
  1308. }
  1309.  
  1310. int postnews(Mail_Socket * NNTP_sock, int cug)
  1311. {
  1312.   char s[181], s1[12], s2[5], fn[201], *ss;
  1313.   int f1, nlines, len, tlen;
  1314.   FILE *fp;
  1315.   static char _temp_buffer[STR];
  1316.   struct ffblk ff;
  1317.  
  1318.   sprintf(fn, "%s\\OUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
  1319.   f1 = findfirst(fn, &ff, 0);
  1320.   if (f1 != 0) {
  1321.     log_it("\n ■ No outbound news articles to post...");
  1322.     return 1;
  1323.   }
  1324.   while (f1 == 0) {
  1325.     sock_printf(NNTP_sock->sock, "POST");
  1326.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1327.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1328.     if (*_temp_buffer != '3') {
  1329.       if (atoi(_temp_buffer) == 440)
  1330.         log_it("\n ■ No posting allowed to %s!", grouprec[cug].groupname);
  1331.       else
  1332.         log_it("\n ■ Remote error: %s", _temp_buffer);
  1333.       return 0;
  1334.     }
  1335.     fprintf(stderr, "\n ■ Posting article to %s\n", grouprec[cug].groupname);
  1336.     sprintf(s, "%s\\OUTBOUND\\%s", net_data, ff.ff_name);
  1337.     fp = fsh_open(s, "rb");
  1338.     nlines = 0;
  1339.     while (fgets(_temp_buffer, 120, fp) != NULL) {
  1340.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1341.         _temp_buffer[1] = '.';
  1342.         _temp_buffer[2] = 0;
  1343.       }
  1344.       tlen = 0;
  1345.       len = strlen(_temp_buffer);
  1346.       while (tlen < len) {
  1347.         if (!tcp_tick(NNTP_sock->sock)) {
  1348.           fclose(fp);
  1349.           fprintf(stderr, "\n ■ Connection reset by host");
  1350.           return 1;
  1351.         }
  1352.         tlen += sock_fastwrite(NNTP_sock->sock, &_temp_buffer[tlen], len - tlen);
  1353.       }
  1354.       backline();
  1355.       fprintf(stderr, "\r ■ Lines sent : %d", ++nlines);
  1356.     }
  1357.     fclose(fp);
  1358.     sock_printf(NNTP_sock->sock, ".\n");
  1359.     fprintf(stderr, "\n ■ Awaiting acknowledgement - may take several minutes...");
  1360.     log_it("\n ■ Server response : ");
  1361.     sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
  1362.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1363.     log_it("%s", _temp_buffer);
  1364.     if (*_temp_buffer != '2') {
  1365.       if (atoi(_temp_buffer) == 441) {
  1366.         ss = strtok(_temp_buffer, " ");
  1367.         ss = strtok(NULL, " ");
  1368.         if (atoi(ss) == 435)
  1369.           unlink(s);
  1370.         fnsplit(s, NULL, NULL, s1, s2);
  1371.         log_it("\n ■ %s%s not accepted by server - nothing posted", s1, s2);
  1372.       } else
  1373.         log_it("\n ■ Remote error: %s", _temp_buffer);
  1374.     } else {
  1375.       if (unlink(s) == 0)
  1376.         log_it("\n ■ Deleted sent message - %s", s);
  1377.     }
  1378.     f1 = findnext(&ff);
  1379.   }
  1380.   SOCK_READ_ERR(NNTP_sock);
  1381.   return 0;
  1382. }
  1383.  
  1384. void get_subtype(int sub, char *where)
  1385. {
  1386.   int ok;
  1387.   char fn[181], s[81], net_name[21], *ss;
  1388.   FILE *fp;
  1389.  
  1390.   where[0] = 0;
  1391.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1392.   fp = fsh_open(fn, "r");
  1393.   if (!fp)
  1394.     return;
  1395.   ok = 0;
  1396.   while (fgets(s, 80, fp)) {
  1397.     if (s[0] == '!') {
  1398.       if (sub == atoi(&s[1]))
  1399.         ok = 1;
  1400.     }
  1401.     if (ok && (s[0] == '$')) {
  1402.       ss = strtok(s, " ");
  1403.       strcpy(net_name, &ss[1]);
  1404.       ss = strtok(NULL, " ");
  1405.       fclose(fp);
  1406.       if ((stricmp(net_name, "FILENET") == 0)) {
  1407.         trimstr1(ss);
  1408.         strcpy(where, ss);
  1409.         return;
  1410.       } else
  1411.         return;
  1412.     }
  1413.   }
  1414.   fclose(fp);
  1415. }
  1416.  
  1417. unsigned int max_on_sub(int cug)
  1418. {
  1419.   int i, sub, f, max_subs, num_subs;
  1420.   char s[121], subtype[12];
  1421.   unsigned int max;
  1422.  
  1423.   if ((strlen(grouprec[cug].subtype) == 1) &&
  1424.       (grouprec[cug].subtype[0] == '0'))
  1425.     return 0;
  1426.   max_subs = syscfg.max_subs;
  1427.   subboards = (subboardrec *) mallocx(max_subs * sizeof(subboardrec));
  1428.   if (!subboards) {
  1429.     fprintf(stderr, "\b\b\b\bUnable to allocate %ld bytes.",
  1430.             max_subs * sizeof(subboardrec));
  1431.     return 0;
  1432.   }
  1433.   sprintf(s, "%sSUBS.DAT", syscfg.datadir);
  1434.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1435.   if (f < 0) {
  1436.     fprintf(stderr, "\n ■ %s NOT FOUND", s);
  1437.     return 0;
  1438.   }
  1439.   num_subs = (sh_read(f, subboards, (max_subs * sizeof(subboardrec)))) /
  1440.       sizeof(subboardrec);
  1441.   f = sh_close(f);
  1442.   for (i = 0; i < num_subs; i++) {
  1443.     sub = i;
  1444.     fprintf(stderr, "\b\b\b\b%-4d", sub);
  1445.     get_subtype(sub, subtype);
  1446.     if (stricmp(subtype, grouprec[cug].subtype) == 0) {
  1447.       max = subboards[i].maxmsgs;
  1448.       fprintf(stderr, "\b\b\b\b%s - %hu posts.", subtype, max);
  1449.       if (subboards)
  1450.         free(subboards);
  1451.       return max;
  1452.     }
  1453.   }
  1454.   if (subboards)
  1455.     free(subboards);
  1456.   return 0;
  1457. }
  1458.  
  1459. int getnews(char *hostname)
  1460. {
  1461.   int f1, nup, nug, cug, abort, ok, done, firstrun, max_articles, parts;
  1462.   char *p, fn[201], mailname[121], reline[121], s[21], s1[21], pktname[121];
  1463.   char orig_subj[STRING];
  1464.   unsigned int text_len;
  1465.   unsigned short temptype;
  1466.   unsigned long new_articles;
  1467.   net_header_rec nh;
  1468.   struct date dt;
  1469.   struct time tm;
  1470.   struct ffblk ff;
  1471.   static FILE *fp;
  1472.   Mail_Socket *nntp_sock;
  1473.   static char _temp_buffer[STR];
  1474.  
  1475.   abort = cug = 0;
  1476.   sock_init();
  1477.   nntp_sock = netsocket(hostname);
  1478.  
  1479.   if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
  1480.     grouprec[0].groupname[0] = 0;
  1481.     write_groups(0);
  1482.     if (grouprec)
  1483.       free(grouprec);
  1484.     sprintf(fn, "%s\\NEWSRC", net_data);
  1485.     log_it("\n ■ Creating newsgroup list : %s...         ", fn);
  1486.     if (saveactive(nntp_sock, fn) == 1) {
  1487.       if (sendauthinfo(nntp_sock) == 0)
  1488.         saveactive(nntp_sock, fn);
  1489.     }
  1490.     nntp_shutdown(nntp_sock);
  1491.     free_Mail_Socket(nntp_sock);
  1492.     return 0;
  1493.   }
  1494.   nug = nup = 1;
  1495.   while ((cug < ngroups) && (!abort)) {
  1496.     if (kbhit()) {
  1497.       if (getch() == 27) {
  1498.         log_it("\n ■ Aborting news retrieval session...");
  1499.         if (fp)
  1500.           fclose(fp);
  1501.         grouprec[cug].lastread = cur_article;
  1502.         write_groups(1);
  1503.         nntp_shutdown(nntp_sock);
  1504.         free_Mail_Socket(nntp_sock);
  1505.         return 1;
  1506.       }
  1507.     }
  1508.     if (nup) {
  1509.       nup = 0;
  1510.       if (grouprec[cug].subtype) {
  1511.         if (fp)
  1512.           fclose(fp);
  1513.         write_groups(0);
  1514.         name_packet(pktname);
  1515.         if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1516.           log_it("\n ■ Unable to create %s!", pktname);
  1517.           qexit(nntp_sock, 1);
  1518.         } else {
  1519.           fnsplit(pktname, NULL, NULL, s, s1);
  1520.           fprintf(stderr, "\n ■ Creating new packet : %s%s", s, s1);
  1521.         }
  1522.       } else {
  1523.         if (fp) {
  1524.           fclose(fp);
  1525.         }
  1526.       }
  1527.     }
  1528.     if (nug) {
  1529.       cur_article = ++grouprec[cug].lastread;
  1530.       nug = 0;
  1531.       while (1) {
  1532.         if (cgroup(nntp_sock, grouprec[cug].groupname)) {
  1533.           if (cgroup(nntp_sock, grouprec[cug].groupname) == 2) {
  1534.             if (sendauthinfo(nntp_sock) == 0)
  1535.               continue;
  1536.             else
  1537.               return 1;
  1538.           }
  1539.           log_it("\n ■ Invalid newsgroup \"%s\" - removed from NEWS.RC.",
  1540.                  grouprec[cug].groupname);
  1541.           grouprec[cug].groupname[0] = 0;
  1542.           if (++bogus >= 10) {
  1543.             log_it("\n ■ More than 10 invalid newsgroups... possible NEWS.RC error!");
  1544.             qexit(nntp_sock, 10);
  1545.           }
  1546.           nug = 1;
  1547.           break;
  1548.         } else
  1549.           break;
  1550.       }
  1551.       if (!nug) {
  1552.         log_it("\n ■ Requesting %s... ", grouprec[cug].groupname);
  1553.         if (grouprec[cug].lastread < cur_first)
  1554.           grouprec[cug].lastread = cur_first;
  1555.         if (grouprec[cug].lastread > cur_last) {
  1556.           grouprec[cug].lastread = cur_last;
  1557.           log_it("no new articles.");
  1558.           nug = 1;
  1559.         } else {
  1560.           new_articles = cur_last - grouprec[cug].lastread + 1;
  1561.           log_it("%lu new article%s.        ",
  1562.                  cur_last - grouprec[cug].lastread + 1,
  1563.                  new_articles == 1 ? "" : "s");
  1564.           if (new_articles > 250) {
  1565.             fprintf(stderr, "\n ■ Maximum posts allowed on subtype     ");
  1566.             max_articles = max_on_sub(cug);
  1567.             if (max_articles && (new_articles > max_articles)) {
  1568.               log_it("\n ■ Requesting most recent %d articles", max_articles);
  1569.               grouprec[cug].lastread = (cur_last - max_articles);
  1570.             }
  1571.           }
  1572.         }
  1573.         postnews(nntp_sock, cug);
  1574.         if (!nug) {
  1575.           if (cur_numa == 0) {
  1576.             log_it("\n ■ No articles available in %s...",
  1577.                    grouprec[cug].groupname);
  1578.             nug = 1;
  1579.             continue;
  1580.           } else {
  1581.             if (cstat(nntp_sock, grouprec[cug].lastread) &&
  1582.                 cstat(nntp_sock, cur_last))
  1583.               nug = 1;
  1584.           }
  1585.         }
  1586.       }
  1587.     } else {
  1588.       if (cnext(nntp_sock)) {
  1589.         fprintf(stderr, "\n ■ End of new articles in %s",
  1590.                 grouprec[cug].groupname);
  1591.         nug = 1;
  1592.         write_groups(1);
  1593.       }
  1594.     }
  1595.     if (!nug) {
  1596.       if ((chead(nntp_sock)) && (checkx(cug))) {
  1597.         if (cur_subject[0]) {
  1598.           treat(cur_subject);
  1599.           if (strlen(cur_subject) > 65)
  1600.             cur_subject[65] = '\0';
  1601.         } else
  1602.           strcpy(cur_subject, "No subject");
  1603.         strcpy(orig_subj, cur_subject);
  1604.         if (cur_from[0]) {
  1605.           treat(cur_from);
  1606.           if (strlen(cur_from) > 45)
  1607.             cur_from[45] = 0;
  1608.         } else
  1609.           strcpy(cur_from, "Unknown");
  1610.         if (cur_replyto[0]) {
  1611.           if (strlen(cur_replyto) > 45)
  1612.             cur_replyto[45] = 0;
  1613.         }
  1614.         strncpy(_temp_buffer, orig_subj, 55);
  1615.         _temp_buffer[55] = '\0';
  1616.         fprintf(stderr, "\n ■ [%lu/%lu] : %s ", cur_article,
  1617.                 cur_last, _temp_buffer);
  1618.         ok = savebody(nntp_sock, cug, &abort);
  1619.         if (ok && grouprec[cug].subtype) {
  1620.           strcpy(msgarea, grouprec[cug].groupname);
  1621.           sprintf(msgto, "All");
  1622.           sprintf(fn, "%s\\INPUT*.MSG", tmpdir);
  1623.           done = 1;
  1624.           parts = 0;
  1625.           if (findfirst(fn, &ff, 0) == 0) {
  1626.             parts = 1;
  1627.             done = 0;
  1628.           }
  1629.           firstrun = 1;
  1630.           while (!done) {
  1631.             sprintf(fn, "%s\\%s", tmpdir, ff.ff_name);
  1632.             f1 = sh_open1(fn, O_RDONLY | O_BINARY);
  1633.             text_len = (unsigned int) filelength(f1);
  1634.             if (text_len > 32000L) {
  1635.               fprintf(stderr, "\n ■ Truncating %lu bytes from input file",
  1636.                       text_len - 32000L);
  1637.               text_len = 32000;
  1638.             }
  1639.             p = (char *) malloca(32767);
  1640.             if (!p) {
  1641.               log_it("\n ■ Insufficient memory to read entire message");
  1642.               qexit(nntp_sock, 1);
  1643.             }
  1644.             sh_read(f1, (void *) p, text_len);
  1645.             sh_close(f1);
  1646.             temptype = atoi(grouprec[cug].subtype);
  1647.             nh.tosys = sy;
  1648.             nh.touser = 0;
  1649.             nh.fromsys = 32767;
  1650.             nh.fromuser = 0;
  1651.             if (!temptype) {
  1652.               nh.main_type = main_type_new_post;
  1653.               nh.minor_type = 0;
  1654.             } else {
  1655.               nh.main_type = main_type_pre_post;
  1656.               nh.minor_type = temptype;
  1657.             }
  1658.             nh.list_len = 0;
  1659.             gettime(&tm);
  1660.             getdate(&dt);
  1661.             nh.daten = dostounix(&dt, &tm);
  1662.             nh.method = 0;
  1663.             if (parts > 1) {
  1664.               sprintf(_temp_buffer, "%d%s ", parts, ordinal_text(parts));
  1665.               strcat(_temp_buffer, orig_subj);
  1666.               strcpy(cur_subject, _temp_buffer);
  1667.               if (strlen(cur_subject) > 72)
  1668.                 cur_subject[72] = '\0';
  1669.               else
  1670.                 cur_subject[strlen(cur_subject)] = '\0';
  1671.             }
  1672.             nh.length = text_len + strlen(cur_subject) + 1;
  1673.             strncpy(mailname, cur_replyto, 46);
  1674.             strcat(mailname, "\r\n");
  1675.             nh.length += strlen(mailname);
  1676.             nh.length += 24 + 2;
  1677.             if (nh.main_type == main_type_new_post)
  1678.               nh.length += strlen(grouprec[cug].subtype) + 1;
  1679.             if (firstrun) {
  1680.               firstrun = 0;
  1681.               if (strncmpi(cur_articleid, "re: ", 4) == 0) {
  1682.                 strncpy(reline, cur_articleid, 60);
  1683.                 sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
  1684.               }
  1685.             }
  1686.             nh.length += strlen(cur_articleid);
  1687.             fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1688.             if (nh.main_type == main_type_new_post)
  1689.               fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
  1690.             fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
  1691.             fsh_write(mailname, sizeof(char), strlen(mailname), fp);
  1692.             strncpy(_temp_buffer, ctime(&(time_t) nh.daten), 24);
  1693.             _temp_buffer[24] = '\0';
  1694.             strcat(_temp_buffer, "\r\n");
  1695.             fsh_write(_temp_buffer, sizeof(char), strlen(_temp_buffer), fp);
  1696.             sprintf(_temp_buffer, "%s\n\n", cur_articleid);
  1697.             fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
  1698.             fsh_write(p, sizeof(char), text_len, fp);
  1699.             if (p)
  1700.               free(p);
  1701.             unlink(fn);
  1702.             if (findnext(&ff) == 0) {
  1703.               done = 0;
  1704.               ++parts;
  1705.             } else
  1706.               done = 1;
  1707.           }
  1708.         }
  1709.         grouprec[cug].lastread = cur_article;
  1710.       } else
  1711.         grouprec[cug].lastread = cur_article + 1;
  1712.       if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
  1713.         nup = 1;
  1714.       if (abort == 2) {
  1715.         write_groups(1);
  1716.         nug = 1;
  1717.         abort = 0;
  1718.       }
  1719.     }
  1720.     if (nug) {
  1721.       ++cug;
  1722.       if (((strlen(grouprec[cug].subtype) == 1) &&
  1723.            (grouprec[cug].subtype[0] == '0')) && (grouprec[cug].subtype)) {
  1724.         nup = 1;
  1725.       } else {
  1726.         if ((grouprec[cug - 1].subtype) &&
  1727.             ((strlen(grouprec[cug].subtype) == 1) &&
  1728.              (grouprec[cug].subtype[0] == '0'))) {
  1729.           if (fp) {
  1730.             fclose(fp);
  1731.           }
  1732.         }
  1733.       }
  1734.     }
  1735.   }
  1736.   if (fp)
  1737.     fclose(fp);
  1738.   if (abort)
  1739.     log_it("\n ■ Session aborted from keyboard");
  1740.   write_groups(1);
  1741.   nntp_shutdown(nntp_sock);
  1742.   free_Mail_Socket(nntp_sock);
  1743.   return 0;
  1744. }
  1745.  
  1746. void main(int argc, char *argv[])
  1747. {
  1748.   int f, done;
  1749.   char s[201], fn[MAXPATH], *ss;
  1750.   FILE *fp;
  1751.   struct tm *time_now;
  1752.   time_t some;
  1753.  
  1754.   cursor('S');
  1755.   cursor('H');
  1756.   fprintf(stderr, "\n ■ %s", version);
  1757.   if (argc != 4)
  1758.     err_exit(EXIT_FAILURE, "\n ■ Invalid arguments for %s", argv[0]);
  1759.   ss = getenv("WWIV_INSTANCE");
  1760.   if (ss) {
  1761.     instance = atoi(ss);
  1762.     if ((instance <= 0) || (instance >= 1000)) {
  1763.       log_it("\n ■ WWIV_INSTANCE set to %d.  Can only be 1..999!", instance);
  1764.       instance = 1;
  1765.     }
  1766.   } else
  1767.     instance = 1;
  1768.   SOCK_DELAY = 120;
  1769.   get_dir(maindir, 0);
  1770.   strcpy(net_data, argv[1]);
  1771.   strcpy(serverhost, argv[2]);
  1772.   if (get_nb_version())
  1773.     multitasker = 8;
  1774.   else
  1775.     detect_multitask();
  1776.   switch (multitasker) {
  1777.     case 1:
  1778.       get_dv_version();
  1779.       break;
  1780.     case 2:
  1781.       get_win_version();
  1782.       break;
  1783.     case 3:
  1784.       get_dv_version();
  1785.       break;
  1786.     case 4:
  1787.     case 5:
  1788.     case 6:
  1789.     case 7:
  1790.       break;
  1791.     case 8:
  1792.       multitasker = 1;
  1793.       break;
  1794.     default:
  1795.       break;
  1796.   }
  1797.   time(&some);
  1798.   time_now = localtime(&some);
  1799.   strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1800.            time_now);
  1801.   sprintf(fn, "%s\\NEWS.LOG", net_data);
  1802.   if ((fp = fsh_open(fn, "at")) != NULL) {
  1803.     fprintf(fp, s);
  1804.     fclose(fp);
  1805.   }
  1806.   sprintf(tmpdir, "%s\\SPOOL", net_data);
  1807.   sy = atoi(argv[3]);
  1808.   sprintf(s, "%s\\CONFIG.DAT", maindir);
  1809.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1810.   if (f < 0)
  1811.     err_exit(EXIT_FAILURE, "\n ■ %s NOT FOUND.", s);
  1812.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1813.   sh_close(f);
  1814.   sprintf(newsrc, "%s\\NEWS.RC", net_data);
  1815.   read_groups();
  1816.   if (ngroups == 0)
  1817.     err_exit(EXIT_FAILURE, "\n ■ Unable to access newsgroup file: %s!", newsrc);
  1818.   if (stricmp(grouprec[0].groupname, "newsrc") == 0)
  1819.     log_it("\n ■ Retrieving current newsgroup listing from %s",
  1820.            serverhost);
  1821.   else
  1822.     log_it("\n ■ %u newsgroup%s defined in %s", ngroups,
  1823.            ngroups == 1 ? "" : "s", strlwr(newsrc));
  1824.   crossposts = 10;
  1825.   sprintf(fn, "%s\\NET.INI", maindir);
  1826.   fp = fsh_open(fn, "rt");
  1827.   if (!fp)
  1828.     fprintf(stderr, "\n ■ Unable to read %s", fn);
  1829.   else {
  1830.     done = 0;
  1831.     while ((fgets(s, 80, fp)) && (!done)) {
  1832.       ss = NULL;
  1833.       stripspace(s);
  1834.       if ((s[0] == ';') || (s[0] == '\n') || (s[0]== '['))
  1835.         continue;
  1836.       if (strlen(s) == 0)
  1837.         continue;
  1838.       if (strnicmp(s, "XPOSTS", 6) == 0) {
  1839.         ss = strtok(s, "=");
  1840.         if (ss) {
  1841.           ss = strtok(NULL, "\n");
  1842.           trimstr1(ss);
  1843.           crossposts = atoi(ss);
  1844.           if (crossposts == 0)
  1845.             crossposts = 1;
  1846.           if (crossposts > 99)
  1847.             crossposts = 10;
  1848.           done = 1;
  1849.         }
  1850.       }
  1851.     }
  1852.   }
  1853.   if (getnews(serverhost))
  1854.     err_exit(EXIT_FAILURE, "\n ■ Exiting program.");
  1855.   if (grouprec)
  1856.     free(grouprec);
  1857.   grouprec = NULL;
  1858.   cd_to(maindir);
  1859.   log_it("\n ■ NEWS succesfully completed processing %d newsgroups", ngroups);
  1860.   log_it("\n ■ Trimming NEWS.LOG to %d entries.", MAX_LOG);
  1861.   trim_log();
  1862.   err_exit(EXIT_SUCCESS, "\n ■ Normal program termination");
  1863. }
  1864.