home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B45.ZIP / NEWS.C < prev    next >
C/C++ Source or Header  |  1997-10-03  |  51KB  |  1,865 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.     if (!(h = resolve(host)))
  1043.       err_exit(EXIT_FAILURE, "\n ■ Could not resolve %s... aborting", host);
  1044.   if ((NNTP_sock = (Mail_Socket *) malloc(sizeof(Mail_Socket))) == NULL)
  1045.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1046.   if ((NNTP_sock->sock = (tcp_Socket *) malloc(sizeof(tcp_Socket))) == NULL) {
  1047.     free(NNTP_sock);
  1048.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1049.   }
  1050.   if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
  1051.     free_Mail_Socket(NNTP_sock);
  1052.     err_exit(EXIT_FAILURE, "\n ■ TCP socket open failed... aborting");
  1053.   }
  1054.   sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
  1055.   sock_wait_established(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1056.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1057.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1058.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1059.   switch (reply) {
  1060.     case 200:
  1061.       log_it(0, "\n ■ Connection to %s accepted...", host);
  1062.       break;
  1063.     case 502:
  1064.       free_Mail_Socket(NNTP_sock);
  1065.       err_exit(EXIT_FAILURE, "\n ■ Connection to %s refused... try again later.", host);
  1066.       break;
  1067.     case 503:
  1068.       free_Mail_Socket(NNTP_sock);
  1069.       err_exit(EXIT_FAILURE, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
  1070.       break;
  1071.     default:
  1072.       free_Mail_Socket(NNTP_sock);
  1073.       err_exit(EXIT_FAILURE, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
  1074.       break;
  1075.   }
  1076.   return (NNTP_sock);
  1077.   SOCK_READ_ERR(NNTP_sock);
  1078.   return 0;
  1079. }
  1080.  
  1081. int cnext(Mail_Socket * NNTP_sock)
  1082. {
  1083.   char *p, *q;
  1084.  
  1085.   sock_printf(NNTP_sock->sock, "NEXT");
  1086.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1087.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1088.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  1089.   if (reply == 421)
  1090.     return -1;
  1091.   else if (reply == 223) {
  1092.     cur_article = reparticle;
  1093.     p = _temp_buffer;
  1094.     q = cur_articleid;
  1095.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  1096.       p++;
  1097.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  1098.       *q++ = *p++;
  1099.     *q++ = '>';
  1100.     *q++ = '\0';
  1101.     return 0;
  1102.   } else
  1103.     log_it(0, "\n ■ Unknown cnext error : %s", _temp_buffer);
  1104.   SOCK_READ_ERR(NNTP_sock);
  1105.   return -1;
  1106. }
  1107.  
  1108. char *stripspace(char *str)
  1109. {
  1110.   char *obuf, *nbuf;
  1111.  
  1112.   if (str) {
  1113.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1114.       if (!isspace(*obuf))
  1115.         *nbuf++ = *obuf;
  1116.     }
  1117.     *nbuf = NULL;
  1118.   }
  1119.   return (str);
  1120. }
  1121.  
  1122.  
  1123. int sendauthinfo(Mail_Socket * NNTP_sock)
  1124. {
  1125.   char s[MAXPATH], line[121], name[21], pass[31], *ss;
  1126.   FILE *fp;
  1127.  
  1128.   output("\n ■ Server requested authentication information.");
  1129.   sprintf(s, "%s\\NET.INI", maindir);
  1130.   if ((fp = fsh_open(s, "rt")) == NULL) {
  1131.     output("\n ■ Unable to open %s.", s);
  1132.     return 1;
  1133.   }
  1134.   while (fgets(line, 80, fp)) {
  1135.     ss = NULL;
  1136.     stripspace(line);
  1137.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == '['))
  1138.       continue;
  1139.     if (strlen(line) == 0)
  1140.       continue;
  1141.     if (strnicmp(line, "NEWSNAME", 8) == 0) {
  1142.       ss = strtok(line, "=");
  1143.       if (ss) {
  1144.         ss = strtok(NULL, "\n");
  1145.         trimstr1(ss);
  1146.         name[0] = 0;
  1147.         strcpy(name, ss);
  1148.       }
  1149.     }
  1150.     if (strnicmp(line, "NEWSPASS", 8) == 0) {
  1151.       ss = strtok(line, "=");
  1152.       if (ss) {
  1153.         ss = strtok(NULL, "\n");
  1154.         trimstr1(ss);
  1155.         pass[0] = 0;
  1156.         strcpy(pass, ss);
  1157.       }
  1158.     }
  1159.   }
  1160.   if (fp != NULL)
  1161.     fclose(fp);
  1162.   if ((name[0] == 0) || (pass[0] == 0)) {
  1163.     output("\n ■ NEWSNAME or NEWSPASS not properly defined!");
  1164.     return 1;
  1165.   }
  1166.   while (1) {
  1167.     sprintf(_temp_buffer, "authinfo user %s", name);
  1168.     sock_printf(NNTP_sock->sock, _temp_buffer);
  1169.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1170.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1171.     sscanf(_temp_buffer, "%hu %s", &reply, s);
  1172.     if (reply == 381) {
  1173.       sprintf(_temp_buffer, "authinfo pass %s", pass);
  1174.       sock_printf(NNTP_sock->sock, _temp_buffer);
  1175.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1176.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1177.       sscanf(_temp_buffer, "%hu %s", &reply, s);
  1178.       if (reply == 281) {
  1179.         output("\n ■ Authentication accepted.  Continuing news retrieval session.");
  1180.         return 0;
  1181.       } else {
  1182.         output("\n ■ Authentication failed.  Aborting news retrieval session.");
  1183.         return 1;
  1184.       }
  1185.     } else {
  1186.       output("\n ■ Unknown response \"%hu\" from server.", reply);
  1187.       return 1;
  1188.     }
  1189.   }
  1190.   SOCK_READ_ERR(NNTP_sock);
  1191.   return -1;
  1192. }
  1193.  
  1194. int saveactive(Mail_Socket * NNTP_sock, char *fn)
  1195. {
  1196.   char s[181], group[256], act;
  1197.   long to, from;
  1198.   int count, done;
  1199.   FILE *fp;
  1200.  
  1201.   if ((fp = fsh_open(fn, "w")) == NULL) {
  1202.     perror(fn);
  1203.     return -1;
  1204.   }
  1205.   done = 0;
  1206.   while (!done) {
  1207.     sock_printf(NNTP_sock->sock, "LIST");
  1208.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1209.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1210.     sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  1211.     if (reply == 215) {
  1212.       count = 0;
  1213.       while (1) {
  1214.         if (count++ % 25 == 0)
  1215.           output("\b\b\b\b\b\b\b%-7d", count);
  1216.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1217.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1218.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  1219.           break;
  1220.         sscanf(_temp_buffer, "%s %ld %ld %c", group, &to, &from, &act);
  1221.         sprintf(s, "%s %ld\n", group, to);
  1222.         fsh_write(s, sizeof(char), strlen(s), fp);
  1223.       }
  1224.       log_it(0, "\n ■ %d total newsgroups available on %s", count, serverhost);
  1225.       if (fp != NULL)
  1226.         fclose(fp);
  1227.       return 0;
  1228.     } else {
  1229.       if (reply == 480) {
  1230.         if (fp != NULL)
  1231.           fclose(fp);
  1232.         return 1;
  1233.       } else {
  1234.         log_it(0, "\n ■ Unknown saveactive error : %s", _temp_buffer);
  1235.         if (fp != NULL)
  1236.           fclose(fp);
  1237.         done = 1;
  1238.       }
  1239.     }
  1240.   }
  1241.   SOCK_READ_ERR(NNTP_sock);
  1242.   return -1;
  1243. }
  1244.  
  1245. int checkx(int cug)
  1246. {
  1247.   char *ptr, *ptr2, *ptr3, buf[256];
  1248.   int i, max;
  1249.  
  1250. /*
  1251.   ptr = strtok(cur_organization, "*");
  1252.   trimstr1(ptr);
  1253.   if (strncmpi(ptr, syscfg.systemname, strlen(syscfg.systemname)) == 0) {
  1254.     log_it(0, "\n ■ Skipping message - originally posted on %s.", syscfg.systemname);
  1255.     return 0;
  1256.   }
  1257. */
  1258.   sprintf(buf, "%s!%s", POPNAME, POPDOMAIN);
  1259.   if (strstr(cur_path, buf) != 0) {
  1260.     log_it(0, "\n ■ Local post \"%s\" skipped.", cur_subject);
  1261.     return 0;
  1262.   }
  1263.  
  1264.   ptr = cur_newsgroups;
  1265.   while (*ptr == ' ')
  1266.     ptr++;
  1267.   max = 0;
  1268.   while (1) {
  1269.     if (*ptr == 0)
  1270.       break;
  1271.     if (*ptr == ',') {
  1272.       ptr++;
  1273.       ++max;
  1274.     }
  1275.     while (*ptr == ' ')
  1276.       ptr++;
  1277.     ptr2 = ptr;
  1278.     ptr3 = buf;
  1279.     while (*ptr2 != 0 && *ptr2 != ',')
  1280.       *ptr3++ = *ptr2++;
  1281.     *ptr3 = 0;
  1282.     while (*(--ptr3) == ' ')
  1283.       *ptr3 = 0;
  1284.     ptr = ptr2;
  1285.     for (i = 0; i < cug; i++) {
  1286.       if (strcmpi(buf, grouprec[i].groupname) == 0) {
  1287.         output("\n ■ Skipping message - already posted in %s.",
  1288.                 grouprec[i].groupname);
  1289.         return 0;
  1290.       }
  1291.     }
  1292.     if ((crossposts > 0) && (max > crossposts)) {
  1293.       output("\n ■ Skipping message - crossposted to more than %hu newsgroups.",
  1294.           crossposts);
  1295.       return 0;
  1296.     }
  1297.   }
  1298.   return 1;
  1299. }
  1300.  
  1301. int postnews(Mail_Socket * NNTP_sock, int cug)
  1302. {
  1303.   char s[181], s1[12], s2[5], fn[201], *ss;
  1304.   int f1, nlines, len, tlen;
  1305.   FILE *fp;
  1306.   struct ffblk ff;
  1307.  
  1308.   sprintf(fn, "%s\\OUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
  1309.   f1 = findfirst(fn, &ff, 0);
  1310.   if (f1 != 0) {
  1311.     log_it(0, "\n ■ No outbound news articles to post...");
  1312.     return 1;
  1313.   }
  1314.   while (f1 == 0) {
  1315.     sock_printf(NNTP_sock->sock, "POST");
  1316.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1317.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1318.     if (*_temp_buffer != '3') {
  1319.       if (atoi(_temp_buffer) == 440)
  1320.         log_it(1, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
  1321.       else
  1322.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1323.       return 0;
  1324.     }
  1325.     output("\n ■ Posting article to %s\n", grouprec[cug].groupname);
  1326.     sprintf(s, "%s\\OUTBOUND\\%s", net_data, ff.ff_name);
  1327.     fp = fsh_open(s, "rb");
  1328.     nlines = 0;
  1329.     while (fgets(_temp_buffer, 120, fp) != NULL) {
  1330.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1331.         _temp_buffer[1] = '.';
  1332.         _temp_buffer[2] = 0;
  1333.       }
  1334.       tlen = 0;
  1335.       len = strlen(_temp_buffer);
  1336.       while (tlen < len) {
  1337.         if (!tcp_tick(NNTP_sock->sock)) {
  1338.           if (fp != NULL)
  1339.             fclose(fp);
  1340.           output("\n ■ Connection reset by host");
  1341.           return 1;
  1342.         }
  1343.         tlen += sock_fastwrite(NNTP_sock->sock, &_temp_buffer[tlen], len - tlen);
  1344.       }
  1345.       backline();
  1346.       output("\r ■ Lines sent : %d", ++nlines);
  1347.     }
  1348.     if (fp != NULL)
  1349.       fclose(fp);
  1350.     sock_printf(NNTP_sock->sock, ".\n");
  1351.     output("\n ■ Awaiting acknowledgement - may take several minutes...");
  1352.     log_it(0, "\n ■ Server response : ");
  1353.     sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
  1354.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1355.     log_it(0, "%s", _temp_buffer);
  1356.     if (*_temp_buffer != '2') {
  1357.       if (atoi(_temp_buffer) == 441) {
  1358.         ss = strtok(_temp_buffer, " ");
  1359.         ss = strtok(NULL, " ");
  1360.         if (atoi(ss) == 435)
  1361.           unlink(s);
  1362.         fnsplit(s, NULL, NULL, s1, s2);
  1363.         log_it(0, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
  1364.       } else
  1365.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1366.     } else {
  1367.       if (unlink(s) == 0)
  1368.         log_it(0, "\n ■ Deleted sent message - %s", s);
  1369.     }
  1370.     f1 = findnext(&ff);
  1371.   }
  1372.   SOCK_READ_ERR(NNTP_sock);
  1373.   return 0;
  1374. }
  1375.  
  1376. void get_subtype(int sub, char *where)
  1377. {
  1378.   int ok, which;
  1379.   char fn[181], s[81], net_name[21], *ss;
  1380.   FILE *fp;
  1381.  
  1382.   where[0] = 0;
  1383.   which = sub;
  1384.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1385.   if ((fp = fsh_open(fn, "r")) == NULL)
  1386.     return;
  1387.   ok = 0;
  1388.   while (fgets(s, 80, fp)) {
  1389.     if (s[0] == '!') {
  1390.       if (which == atoi(&s[1]))
  1391.         ok = 1;
  1392.     }
  1393.     if (ok && (s[0] == '$')) {
  1394.       ss = strtok(s, " ");
  1395.       strcpy(net_name, &ss[1]);
  1396.       ss = strtok(NULL, " ");
  1397.       if (fp != NULL)
  1398.         fclose(fp);
  1399.       if ((stricmp(net_name, "FILENET") == 0)) {
  1400.         trimstr1(ss);
  1401.         strcpy(where, ss);
  1402.         return;
  1403.       } else
  1404.         return;
  1405.     }
  1406.   }
  1407.   if (fp != NULL)
  1408.     fclose(fp);
  1409. }
  1410.  
  1411. unsigned short max_on_sub(int cug)
  1412. {
  1413.   int i, num_subs;
  1414.   char fn[MAXPATH], subtype[12];
  1415.   unsigned short max;
  1416.   subboardrec sub;
  1417.   FILE *fp;
  1418.  
  1419.   max = 0;
  1420.   if ((strlen(grouprec[cug].subtype) == 1) && (grouprec[cug].subtype[0] == '0'))
  1421.     return max;
  1422.   sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
  1423.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  1424.     output("\n ■ Unable to read %s.", fn);
  1425.     return max;
  1426.   } else {
  1427.     fseek(fp, 0L, SEEK_END);
  1428.     num_subs = (int) (ftell(fp) / sizeof(subboardrec));
  1429.     for (i = 0; i < num_subs; i++) {
  1430.       output("\b\b\b\b%-4d", i);
  1431.       fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
  1432.       fread(&sub, sizeof(subboardrec), 1, fp);
  1433.       get_subtype(i, subtype);
  1434.       if (stricmp(subtype, grouprec[cug].subtype) == 0) {
  1435.         max = sub.maxmsgs;
  1436.         output("\b\b\b\b%s (%s) - %hu posts.", sub.name, subtype, max);
  1437.         break;
  1438.       }
  1439.     }
  1440.   }
  1441.   if (fp != NULL)
  1442.     fclose(fp);
  1443.   return max;
  1444. }
  1445.  
  1446.  
  1447. int getnews(Mail_Socket * NNTP_sock)
  1448. {
  1449.   int f1, nup, nug, cug, abort, ok, done, firstrun, parts, bogus;
  1450.   char *p, fn[201], mailname[121], reline[121], s[21], s1[21], pktname[121];
  1451.   char ch, orig_subj[STRING];
  1452.   unsigned int text_len;
  1453.   unsigned short temptype;
  1454.   long new_articles, max_articles;
  1455.   net_header_rec nh;
  1456.   struct ffblk ff;
  1457.   FILE *fp;
  1458.  
  1459.   abort = cug = bogus = 0;
  1460.  
  1461.   if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
  1462.     grouprec[0].groupname[0] = 0;
  1463.     write_groups(0);
  1464.     if (grouprec)
  1465.       farfree(grouprec);
  1466.     sprintf(fn, "%s\\NEWSRC", net_data);
  1467.     log_it(0, "\n ■ Creating newsgroup list : %s...         ", fn);
  1468.     if (saveactive(NNTP_sock, fn) == 1) {
  1469.       if (sendauthinfo(NNTP_sock) == 0)
  1470.         saveactive(NNTP_sock, fn);
  1471.     }
  1472.     nntp_shutdown(NNTP_sock);
  1473.     free_Mail_Socket(NNTP_sock);
  1474.     return 0;
  1475.   }
  1476.   nug = nup = 1;
  1477.   while ((cug < ngroups) && (!abort)) {
  1478.     if (nup) {
  1479.       nup = 0;
  1480.       if (grouprec[cug].subtype) {
  1481.         if (fp != NULL)
  1482.           fclose(fp);
  1483.         write_groups(0);
  1484.         name_packet(pktname);
  1485.         if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1486.           log_it(0, "\n ■ Unable to create %s!", pktname);
  1487.           qexit(NNTP_sock, 1);
  1488.         } else {
  1489.           fnsplit(pktname, NULL, NULL, s, s1);
  1490.           output("\n ■ Creating new packet : %s%s", s, s1);
  1491.         }
  1492.       } else {
  1493.         if (fp != NULL)
  1494.           fclose(fp);
  1495.       }
  1496.     }
  1497.     if (nug) {
  1498.       nug = 0;
  1499.       cur_article = ++grouprec[cug].lastread;
  1500.       while (1) {
  1501.         if (cgroup(NNTP_sock, grouprec[cug].groupname)) {
  1502.           if (cgroup(NNTP_sock, grouprec[cug].groupname) == 2) {
  1503.             if (sendauthinfo(NNTP_sock) == 0)
  1504.               continue;
  1505.             else
  1506.               return 1;
  1507.           }
  1508.           log_it(1, "\n ■ Error accessing newsgroup \"%s\".",
  1509.                  grouprec[cug].groupname);
  1510.           if (++bogus >= 10) {
  1511.             log_it(0, "\n ■ Too many invalid newsgroups... NEWS.RC error!");
  1512.             qexit(NNTP_sock, 10);
  1513.           }
  1514.           nug = 1;
  1515.           break;
  1516.         } else
  1517.           break;
  1518.       }
  1519.       if (!nug) {
  1520.         log_it(0, "\n ■ Requesting %s... ", grouprec[cug].groupname);
  1521.         if (grouprec[cug].lastread < cur_first)
  1522.           grouprec[cug].lastread = cur_first;
  1523.         if (grouprec[cug].lastread > cur_last) {
  1524.           grouprec[cug].lastread = cur_last;
  1525.           log_it(0, "no new articles.");
  1526.           nug = 1;
  1527.         } else {
  1528.           new_articles = cur_last - grouprec[cug].lastread;
  1529.           if (new_articles)
  1530.             log_it(0, "%ld new article%s.", new_articles + 1,
  1531.                  new_articles == 1L ? "" : "s");
  1532.           else {
  1533.             log_it(0, "no new articles.");
  1534.             nug = 1;
  1535.           }
  1536.           if (new_articles > 250L) {
  1537.             max_articles = 0L;
  1538.             output("\n ■ Maximum posts -     ");
  1539.             max_articles = (long) max_on_sub(cug);
  1540.             if (max_articles && (new_articles > max_articles)) {
  1541.               log_it(0, "\n ■ Requesting most recent %ld articles", max_articles);
  1542.               grouprec[cug].lastread = cur_last - max_articles;
  1543.             }
  1544.           }
  1545.         }
  1546.         postnews(NNTP_sock, cug);
  1547.         if (!nug) {
  1548.           if (cur_numa == 0) {
  1549.             log_it(0, "\n ■ No articles available in %s...",
  1550.                    grouprec[cug].groupname);
  1551.             nug = 1;
  1552.             continue;
  1553.           }
  1554.         }
  1555.       }
  1556.     } else {
  1557.       if (cnext(NNTP_sock) == -1) {
  1558.         output("\n ■ End of new articles in %s",
  1559.                 grouprec[cug].groupname);
  1560.         nug = 1;
  1561.         write_groups(1);
  1562.       }
  1563.     }
  1564.     while (kbhit()) {
  1565.       ch = (getch());
  1566.       switch (ch) {
  1567.         case 27:
  1568.           log_it(0, "\n ■ Aborting news retrieval session...");
  1569.           if (fp != NULL)
  1570.             fclose(fp);
  1571.           nntp_shutdown(NNTP_sock);
  1572.           free_Mail_Socket(NNTP_sock);
  1573.           return 1;
  1574.         case 32:
  1575.           output("\n ■ Skipping group %s... ", grouprec[cug].groupname);
  1576.           write_groups(1);
  1577.           nug = 1;
  1578.           break;
  1579.         default:
  1580.           break;
  1581.       }
  1582.     }
  1583.     if (!nug) {
  1584.       if ((chead(NNTP_sock)) && (checkx(cug))) {
  1585.         if (cur_subject[0]) {
  1586.           treat(cur_subject);
  1587.           if (strlen(cur_subject) > 65)
  1588.             cur_subject[65] = '\0';
  1589.         } else
  1590.           strcpy(cur_subject, "No subject");
  1591.         strcpy(orig_subj, cur_subject);
  1592.         if (cur_from[0]) {
  1593.           treat(cur_from);
  1594.           if (strlen(cur_from) > 45)
  1595.             cur_from[45] = 0;
  1596.         } else
  1597.           strcpy(cur_from, "Unknown");
  1598.         if (cur_replyto[0]) {
  1599.           if (strlen(cur_replyto) > 45)
  1600.             cur_replyto[45] = 0;
  1601.         }
  1602.         strncpy(_temp_buffer, orig_subj, 56);
  1603.         _temp_buffer[56] = '\0';
  1604.         output("\n ■ [%ld/%ld] : %s ", grouprec[cug].lastread,
  1605.                 cur_last, _temp_buffer);
  1606.         abort = 0;
  1607.         ok = savebody(NNTP_sock, cug, &abort);
  1608.         if (ok && grouprec[cug].subtype) {
  1609.           sprintf(fn, "%s\\INPUT*.MSG", tmpdir);
  1610.           done = 1;
  1611.           parts = 0;
  1612.           if (findfirst(fn, &ff, 0) == 0) {
  1613.             parts = 1;
  1614.             done = 0;
  1615.           }
  1616.           firstrun = 1;
  1617.           while (!done) {
  1618.             sprintf(fn, "%s\\%s", tmpdir, ff.ff_name);
  1619.             f1 = sh_open1(fn, O_RDONLY | O_BINARY);
  1620.             text_len = (unsigned int) filelength(f1);
  1621.             if (text_len > 32000L) {
  1622.               output("\n ■ Truncating %lu bytes from input file",
  1623.                       text_len - 32000L);
  1624.               text_len = 32000;
  1625.             }
  1626.             if ((p = (char *) malloca(32767L)) == NULL) {
  1627.               log_it(0, "\n ■ Insufficient memory to read entire message");
  1628.               qexit(NNTP_sock, 1);
  1629.             }
  1630.             sh_read(f1, (void *) p, text_len);
  1631.             sh_close(f1);
  1632.             temptype = atoi(grouprec[cug].subtype);
  1633.             nh.tosys = sy;
  1634.             nh.touser = 0;
  1635.             nh.fromsys = 32767;
  1636.             nh.fromuser = 0;
  1637.             if (!temptype) {
  1638.               nh.main_type = main_type_new_post;
  1639.               nh.minor_type = 0;
  1640.             } else {
  1641.               nh.main_type = main_type_pre_post;
  1642.               nh.minor_type = temptype;
  1643.             }
  1644.             nh.list_len = 0;
  1645.             ++cur_daten;
  1646.             nh.daten = cur_daten;
  1647.             nh.method = 0;
  1648.             if (parts > 1) {
  1649.               sprintf(_temp_buffer, "%d%s ", parts, ordinal_text(parts));
  1650.               strcat(_temp_buffer, orig_subj);
  1651.               strcpy(cur_subject, _temp_buffer);
  1652.               if (strlen(cur_subject) > 72)
  1653.                 cur_subject[72] = '\0';
  1654.               else
  1655.                 cur_subject[strlen(cur_subject)] = '\0';
  1656.             }
  1657.             nh.length = text_len + strlen(cur_subject) + 1;
  1658.             strncpy(mailname, cur_replyto, 46);
  1659.             strcat(mailname, "\r\n");
  1660.             nh.length += strlen(mailname);
  1661.             if (nh.main_type == main_type_new_post)
  1662.               nh.length += strlen(grouprec[cug].subtype) + 1;
  1663.             if (firstrun) {
  1664.               firstrun = 0;
  1665.               if (strncmpi(cur_articleid, "re: ", 4) == 0) {
  1666.                 strncpy(reline, cur_articleid, 60);
  1667.                 sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
  1668.               }
  1669.             }
  1670.             if (!cur_date[0]) {
  1671.               strncpy(cur_date, ctime(&(time_t) nh.daten), 24);
  1672.               cur_date[24] = '\0';
  1673.             }
  1674.             strcat(cur_date, "\r\n");
  1675.             nh.length += strlen(cur_date);
  1676.             nh.length += strlen(cur_articleid);
  1677.             fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1678.             if (nh.main_type == main_type_new_post)
  1679.               fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
  1680.             fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
  1681.             fsh_write(mailname, sizeof(char), strlen(mailname), fp);
  1682.             fsh_write(cur_date, sizeof(char), strlen(cur_date), fp);
  1683.             fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
  1684.             fsh_write(p, sizeof(char), text_len, fp);
  1685.             if (p != NULL)
  1686.               free(p);
  1687.             unlink(fn);
  1688.             if (findnext(&ff) == 0) {
  1689.               done = 0;
  1690.               ++parts;
  1691.             } else
  1692.               done = 1;
  1693.           }
  1694.         }
  1695. //        grouprec[cug].lastread = cur_article;
  1696. //      } else
  1697. //        grouprec[cug].lastread = cur_article + 1;
  1698.       }
  1699.       cur_article = ++grouprec[cug].lastread;
  1700.       if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
  1701.         nup = 1;
  1702.       if (abort == 2) {
  1703.         write_groups(1);
  1704.         nug = 1;
  1705.         abort = 0;
  1706.       }
  1707.     }
  1708.     if (nug) {
  1709.       ++cug;
  1710.       if (((strlen(grouprec[cug].subtype) == 1) &&
  1711.            (grouprec[cug].subtype[0] == '0')) && (grouprec[cug].subtype)) {
  1712.         nup = 1;
  1713.       } else {
  1714.         if ((grouprec[cug - 1].subtype) &&
  1715.             ((strlen(grouprec[cug].subtype) == 1) &&
  1716.              (grouprec[cug].subtype[0] == '0'))) {
  1717.           if (fp != NULL)
  1718.             fclose(fp);
  1719.         }
  1720.       }
  1721.     }
  1722.   }
  1723.   if (fp != NULL)
  1724.     fclose(fp);
  1725.   if (abort)
  1726.     log_it(0, "\n ■ Session aborted from keyboard");
  1727.   write_groups(1);
  1728.   nntp_shutdown(NNTP_sock);
  1729.   free_Mail_Socket(NNTP_sock);
  1730.   return 0;
  1731. }
  1732.  
  1733. void main(int argc, char *argv[])
  1734. {
  1735.   int f;
  1736.   char s[160], fn[MAXPATH], *ss;
  1737.   FILE *fp;
  1738.   struct tm *time_now;
  1739.   struct date dt;
  1740.   struct time tm;
  1741.   time_t some;
  1742.   Mail_Socket *nntp_sock = NULL;
  1743.  
  1744.   cursor('S');
  1745.   cursor('H');
  1746.   output("\n ■ %s", version);
  1747.   if (argc != 4)
  1748.     err_exit(EXIT_FAILURE, "\n ■ Invalid arguments for %s", argv[0]);
  1749.   ss = getenv("WWIV_INSTANCE");
  1750.   if (ss) {
  1751.     instance = atoi(ss);
  1752.     if ((instance <= 0) || (instance >= 1000)) {
  1753.       log_it(0, "\n ■ WWIV_INSTANCE set to %d.  Can only be 1..999!", instance);
  1754.       instance = 1;
  1755.     }
  1756.   } else
  1757.     instance = 1;
  1758.   gettime(&tm);
  1759.   getdate(&dt);
  1760.   cur_daten = dostounix(&dt, &tm);
  1761.   SOCK_DELAY = 120;
  1762.   get_dir(maindir, 0);
  1763.   strcpy(net_data, argv[1]);
  1764. //  strcpy(serverhost, argv[2]);
  1765.   detect_multitask();
  1766.   time(&some);
  1767.   time_now = localtime(&some);
  1768.   strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1769.            time_now);
  1770.   sprintf(fn, "%s\\NEWS.LOG", net_data);
  1771.   if ((fp = fsh_open(fn, "at")) != NULL) {
  1772.     fprintf(fp, s);
  1773.     fclose(fp);
  1774.   }
  1775.   sprintf(tmpdir, "%s\\SPOOL", net_data);
  1776.   sy = atoi(argv[3]);
  1777.   sprintf(s, "%s\\CONFIG.DAT", maindir);
  1778.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1779.   if (f < 0)
  1780.     err_exit(EXIT_FAILURE, "\n ■ %s NOT FOUND.", s);
  1781.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1782.   sh_close(f);
  1783.   sprintf(s, "%s\\NEWS.RC", net_data);
  1784.   read_groups();
  1785.   if (ngroups == 0)
  1786.     err_exit(EXIT_FAILURE, "\n ■ Unable to access newsgroup file: %s!", s);
  1787.   if (stricmp(grouprec[0].groupname, "newsrc") == 0)
  1788.     log_it(0, "\n ■ Retrieving current newsgroup listing from %s.",
  1789.            serverhost);
  1790.   else
  1791.     log_it(0, "\n ■ %u newsgroup%s defined in %s.", ngroups,
  1792.            ngroups == 1 ? "" : "s", s);
  1793.   crossposts = 10;
  1794.   POPNAME[0] = 0;
  1795.   POPDOMAIN[0] = 0;
  1796.   sprintf(fn, "%s\\NET.INI", maindir);
  1797.   if ((fp = fsh_open(fn, "rt")) == NULL)
  1798.     output("\n ■ Unable to read %s", fn);
  1799.   else {
  1800.     while (fgets(s, 100, fp)) {
  1801.       stripspace(s);
  1802.       if ((s[0] == ';') || (s[0] == '\n') || (s[0]== '['))
  1803.         continue;
  1804.       if (strlen(s) == 0)
  1805.         continue;
  1806.       if ((strnicmp(s, "POPNAME", 7) == 0) && (POPNAME[0] == 0)) {
  1807.         ss = strtok(s, "=");
  1808.         if (ss) {
  1809.           ss = strtok(NULL, "\n");
  1810.           trimstr1(ss);
  1811.           strcpy(POPNAME, ss);
  1812.         }
  1813.       }
  1814.       if (strnicmp(s, "FWDNAME", 7) == 0) {
  1815.         ss = strtok(s, "=");
  1816.         if (ss) {
  1817.           ss = strtok(NULL, "\n");
  1818.           trimstr1(ss);
  1819.           strcpy(POPNAME, ss);
  1820.         }
  1821.       }
  1822.       if ((strnicmp(s, "DOMAIN", 6) == 0) && (POPDOMAIN[0] == 0)) {
  1823.         ss = strtok(s, "=");
  1824.         if (ss) {
  1825.           ss = strtok(NULL, "\n");
  1826.           trimstr1(ss);
  1827.           strcpy(POPDOMAIN, ss);
  1828.         }
  1829.       }
  1830.       if (strnicmp(s, "FWDDOM", 6) == 0) {
  1831.         ss = strtok(s, "=");
  1832.         if (ss) {
  1833.           ss = strtok(NULL, "\n");
  1834.           trimstr1(ss);
  1835.           strcpy(POPDOMAIN, ss);
  1836.         }
  1837.       }
  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 > 99)
  1845.             crossposts = 10;
  1846.         }
  1847.       }
  1848.       ss = NULL;
  1849.     }
  1850.     if (fp != NULL)
  1851.       fclose(fp);
  1852.   }
  1853.  
  1854.   nntp_sock = netsocket(argv[2]);
  1855.   if (getnews(nntp_sock))
  1856.     err_exit(EXIT_FAILURE, "\n ■ Exiting program.");
  1857.   if (grouprec)
  1858.     farfree(grouprec);
  1859.   grouprec = NULL;
  1860.   cd_to(maindir);
  1861.   log_it(0, "\n ■ NEWS succesfully completed processing %d newsgroups", ngroups);
  1862.   trim_log();
  1863.   err_exit(EXIT_SUCCESS, "\n ■ Normal program termination");
  1864. }
  1865.