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