home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B25.ZIP / NETWORK.C < prev    next >
C/C++ Source or Header  |  1997-04-28  |  47KB  |  1,836 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <fcntl.h>
  6. #include <sys/stat.h>
  7. #include <ctype.h>
  8. #include <mem.h>
  9. #include <conio.h>
  10. #include <io.h>
  11. #include <share.h>
  12. #include <errno.h>
  13. #include <malloc.h>
  14. #include <dir.h>
  15. #include <time.h>
  16. #include <process.h>
  17. #include <direct.h>
  18. #include "vardec.h"
  19. #include "net.h"
  20. #include "version.h"
  21.  
  22. #define NUL '\0'
  23. #define LAST(s) s[strlen(s)-1]
  24. #define MAX_PATH 79
  25.  
  26. #define SHARE_LEVEL 10
  27. #define WAIT_TIME 10
  28. #define TRIES 100
  29.  
  30. #define MT_DESQVIEW 0x01
  31. #define MT_WINDOWS  0x02
  32. #define MT_OS2      0x04
  33. #define MT_NB       0x40
  34.  
  35. #define VIDEO 0x10
  36.  
  37. #define INI_NETWORK   0x01
  38. #define INI_GENERAL   0x02
  39. #define INI_NEWS      0x04
  40.  
  41. char *version = "Freeware PPP Net Packet Engine " VERSION;
  42. char *author = "Contact Frank Reid at edare@abs.net or 1@8213.WWIVnet for support";
  43.  
  44. unsigned _stklen = 18000;
  45.  
  46. configrec syscfg;
  47. configoverrec syscfgovr;
  48. net_networks_rec netcfg;
  49. net_system_list_rec *netsys;
  50.  
  51. int multitasker = 0, ini_section = 0;
  52. char wwiv_net_no[20], maindir[121];
  53. char net_name[16], net_data[121];
  54. unsigned short net_sysnum;
  55. int num_sys_list, net_num, net_num_max, netnum, ninst;
  56. static int lsl_loaded;
  57.  
  58. char SMTPHOST[60], POPHOST[60], NEWSHOST[60], POPNAME[60], POPPASS[25];
  59.  
  60. char IPADDR[21], NETMASK[21], FWDNAME[60], FWDDOM[60];
  61. char DNS[21], DOMAIN[60], GATEWAY[60], temp_dir[MAXPATH];
  62. unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0, TIMEOUT = 60, SOCK_DELAY = 30, SOCK_INACTIVE = 60;
  63. unsigned int ONECALL = 0, PURGE = 1;
  64. int instance;
  65.  
  66. char *xenviron[50];
  67.  
  68. void dv_pause(void)
  69. {
  70.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  71.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  72.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  73. }
  74.  
  75. void win_pause(void)
  76. {
  77.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  78. }
  79.  
  80. int get_dos_version(void)
  81. {
  82.   _AX = 0x3000;
  83.   geninterrupt(0x21);
  84.   if (_AX % 256 >= 10) {
  85.     multitasker |= MT_OS2;
  86.   }
  87.   return (_AX);
  88. }
  89.  
  90. int get_dv_version(void)
  91. {
  92.   int v;
  93.  
  94.   if (multitasker & MT_OS2)
  95.     return 0;
  96.   _AX = 0x2b01;
  97.   _CX = 0x4445;
  98.   _DX = 0x5351;
  99.   geninterrupt(0x21);
  100.   if (_AL == 0xff) {
  101.     return 0;
  102.   } else {
  103.     v = _BX;
  104.     multitasker |= MT_DESQVIEW;
  105.     return v;
  106.   }
  107. }
  108.  
  109. int get_win_version(void)
  110. {
  111.   int v = 0;
  112.  
  113.   __emit__(0x55, 0x06, 0x53);
  114.   _AX = 0x352f;
  115.   geninterrupt(0x21);
  116.   _AX = _ES;
  117.   if (_AX | _BX) {
  118.     _AX = 0x1600;
  119.     geninterrupt(0x2f);
  120.     v = _AX;
  121.     if (v % 256 <= 1)
  122.       v = 0;
  123.   }
  124.   __emit__(0x5b, 0x07, 0x5d);
  125.   if (v != 0)
  126.     multitasker |= MT_WINDOWS;
  127.   return (v);
  128. }
  129.  
  130. int get_nb_version(void)
  131. {
  132.   _AX = 0;
  133.   geninterrupt(0x2A);
  134.   return (_AH);
  135. }
  136.  
  137. void detect_multitask(void)
  138. {
  139.   get_dos_version();
  140.   get_win_version();
  141.   get_dv_version();
  142. }
  143.  
  144. void giveup_timeslice(void)
  145. {
  146.   if (multitasker) {
  147.     switch (multitasker) {
  148.  case 1: 
  149.  case 3: 
  150.         dv_pause();
  151.         break;
  152.       case 2:
  153.       case 4:
  154.       case 5:
  155.       case 6:
  156.       case 7:
  157.         win_pause();
  158.         break;
  159.       default:
  160.         break;
  161.     }
  162.   }
  163. }
  164.  
  165. char *stripspace(char *str)
  166. {
  167.   char *obuf, *nbuf;
  168.  
  169.   if (str) {
  170.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  171.       if (!isspace(*obuf))
  172.         *nbuf++ = *obuf;
  173.     }
  174.     *nbuf = NULL;
  175.   }
  176.   return (str);
  177. }
  178.  
  179. int sh_write(int handle, void *buffer, unsigned long len)
  180. {
  181.   if (handle == -1) {
  182.     return (-1);
  183.   }
  184.   return (write(handle, buffer, (unsigned) len));
  185. }
  186.  
  187. int sh_open(char *path, int file_access, unsigned fmode)
  188. {
  189.   int handle, count, share;
  190.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  191.  
  192.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  193.     share = SH_DENYRW;
  194.   } else {
  195.     share = SH_DENYWR;
  196.   }
  197.   handle = open(path, file_access | share, fmode);
  198.   if (handle < 0) {
  199.     count = 1;
  200.     fnsplit(path, drive, dir, file, ext);
  201.     if (access(path, 0) != -1) {
  202.       delay(WAIT_TIME);
  203.       handle = open(path, file_access | share, fmode);
  204.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  205.         if (count % 2)
  206.           delay(WAIT_TIME);
  207.         else
  208.           giveup_timeslice();
  209.         count++;
  210.         handle = open(path, file_access | share, fmode);
  211.       }
  212.     }
  213.   }
  214.   return (handle);
  215. }
  216.  
  217. int sh_open1(char *path, int access)
  218. {
  219.   unsigned fmode;
  220.  
  221.   fmode = 0;
  222.   if ((access & O_RDWR) || (access & O_WRONLY))
  223.     fmode |= S_IWRITE;
  224.   if ((access & O_RDWR) || (access & O_RDONLY))
  225.     fmode |= S_IREAD;
  226.   return (sh_open(path, access, fmode));
  227. }
  228.  
  229. int sh_close(int f)
  230. {
  231.   if (f != -1)
  232.     close(f);
  233.   return (-1);
  234. }
  235.  
  236. int sh_read(int handle, void *buf, unsigned len)
  237. {
  238.   if (handle == -1) {
  239.     return (-1);
  240.   }
  241.   return (read(handle, buf, len));
  242. }
  243.  
  244. long sh_lseek(int handle, long offset, int fromwhere)
  245. {
  246.   if (handle == -1) {
  247.     return (-1L);
  248.   }
  249.   return (lseek(handle, offset, fromwhere));
  250. }
  251.  
  252. FILE *fsh_open(char *path, char *fmode)
  253. {
  254.   FILE *f;
  255.   int count, share, md, fd;
  256.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  257.  
  258.   share = SH_DENYWR;
  259.   md = 0;
  260.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  261.     share = SH_DENYRD;
  262.     md = O_RDWR | O_CREAT | O_TRUNC;
  263.   } else
  264.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  265.     share = SH_DENYRD;
  266.     md = O_RDWR | O_CREAT;
  267.   } else {
  268.     md = O_RDONLY;
  269.   }
  270.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  271.     md |= O_BINARY;
  272.   }
  273.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  274.     md &= ~O_RDONLY;
  275.     md |= O_RDWR;
  276.     share = SH_DENYRD;
  277.   }
  278.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  279.   if (fd < 0) {
  280.     count = 1;
  281.     fnsplit(path, drive, dir, file, ext);
  282.     if ((access(path, 0)) != -1) {
  283.       delay(WAIT_TIME);
  284.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  285.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  286.         delay(WAIT_TIME);
  287.         count++;
  288.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  289.       }
  290.     }
  291.   }
  292.   if (fd > 0) {
  293.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  294.       sh_lseek(fd, 0L, SEEK_END);
  295.     f = fdopen(fd, fmode);
  296.     if (!f) {
  297.       close(fd);
  298.     }
  299.   } else
  300.     f = 0;
  301.   return (f);
  302. }
  303.  
  304. void backline(void)
  305. {
  306.   int i;
  307.  
  308.   fprintf(stderr, " ");
  309.   for (i = wherex(); i > 0; i--)
  310.     fprintf(stderr, "\b \b");
  311. }
  312.  
  313.  
  314. int do_spawn(char *cl)
  315. {
  316.   int i, i1, l;
  317.   char *s, *ss[50];
  318.  
  319.   s = strdup(cl);
  320.   ss[0] = s;
  321.   i = 1;
  322.   l = strlen(s);
  323.   for (i1 = 1; i1 < l; i1++)
  324.     if (s[i1] == 32) {
  325.       s[i1] = 0;
  326.       ss[i++] = &(s[i1 + 1]);
  327.     }
  328.   ss[i] = NULL;
  329.   if (MOREINFO)
  330.     fprintf(stderr, "\n");
  331.   i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
  332.   free(s);
  333.   return (i);
  334. }
  335.  
  336. void unload_klos(void)
  337. {
  338.   char s[101];
  339.  
  340.   sprintf(s, "%s\\IPSTUB U", maindir);
  341.   do_spawn(s);
  342.   sprintf(s, "%s\\PPP U", maindir);
  343.   do_spawn(s);
  344.   if (!lsl_loaded) {
  345.     sprintf(s, "%s\\LSL U", maindir);
  346.     do_spawn(s);
  347.   }
  348. }
  349.  
  350. void cd_to(char *s)
  351. {
  352.   char *s1;
  353.   int i, db;
  354.  
  355.   s1 = s;
  356.   i = strlen(s1) - 1;
  357.   db = (s1[i] == '\\');
  358.   if (i == 0)
  359.     db = 0;
  360.   if ((i == 2) && (s1[1] == ':'))
  361.     db = 0;
  362.   if (db)
  363.     s1[i] = 0;
  364.   chdir(s1);
  365.   if (s[1] == ':')
  366.     setdisk(s[0] - 'A');
  367. }
  368.  
  369. void get_dir(char *s, int be)
  370. {
  371.   strcpy(s, "X:\\");
  372.   s[0] = 'A' + getdisk();
  373.   getcurdir(0, s + 3);
  374.   if (be) {
  375.     if (s[strlen(s) - 1] != '\\')
  376.       strcat(s, "\\");
  377.   }
  378. }
  379.  
  380. unsigned char *trimstr1(unsigned char *s)
  381. {
  382.   int i;
  383.   static char *whitespace = " \r\n\t";
  384.  
  385.   i = (int) strlen(s);
  386.   while ((i > 0) && ((char *) _fstrchr(whitespace, s[i - 1]) != NULL))
  387.     --i;
  388.   while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
  389.     memmove(s, s + 1, --i);
  390.   }
  391.   s[i] = NUL;
  392.   return (s);
  393. }
  394.  
  395. char *make_abs_path(unsigned char *checkdir)
  396. {
  397.   char newdir[121];
  398.  
  399.   if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
  400.     cd_to(maindir);
  401.     cd_to(checkdir);
  402.     if (LAST(checkdir) == '\\')
  403.       get_dir(newdir, 1);
  404.     else
  405.       get_dir(newdir, 0);
  406.     cd_to(maindir);
  407.     strcpy(checkdir, newdir);
  408.   }
  409.   return checkdir;
  410. }
  411.  
  412. int exist(char *s)
  413. {
  414.   int i;
  415.   struct ffblk ff;
  416.  
  417.   i = findfirst(s, &ff, 0);
  418.   if (i)
  419.     return (0);
  420.   else
  421.     return (1);
  422. }
  423.  
  424. void set_net_num(int n)
  425. {
  426.   char s[121];
  427.   int f;
  428.  
  429.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  430.   f = sh_open1(s, O_RDONLY | O_BINARY);
  431.   if (f < 0)
  432.     return;
  433.   lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
  434.   sh_read(f, &netcfg, sizeof(net_networks_rec));
  435.   close(f);
  436.   net_num = n;
  437.   net_sysnum = netcfg.sysnum;
  438.   strcpy(net_name, netcfg.name);
  439.   strcpy(net_data, make_abs_path(netcfg.dir));
  440.   if (LAST(net_data) != '\\')
  441.     strcat(net_data, "\\");
  442.   sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
  443. }
  444.  
  445. int make_path(char *s)
  446. {
  447.   unsigned int i;
  448.   char drive, current_path[MAX_PATH], current_drive, *p, *flp;
  449.   union REGS r;
  450.  
  451.   p = flp = strdup(s);
  452.   _getdcwd(0, current_path, MAX_PATH);
  453.   current_drive = *current_path - '@';
  454.   if (LAST(s) == '\\')
  455.     LAST(s) = 0;
  456.   if (p[1] == ':') {
  457.     drive = toupper(p[0]) - 'A' + 1;
  458.     if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
  459.       r.x.ax = 0x4409;
  460.       r.h.bl = drive;
  461.       int86(0x21, &r, &r);
  462.       if (r.x.cflag)
  463.         return -3;
  464.     }
  465.     if (_chdrive(drive)) {
  466.       chdir(current_path);
  467.       _dos_setdrive(current_drive, &i);
  468.       return -2;
  469.     }
  470.     p += 2;
  471.   }
  472.   if (*p == '\\') {
  473.     chdir("\\");
  474.     p++;
  475.   }
  476.   for (; (p = strtok(p, "\\")) != 0; p = 0) {
  477.     if (chdir(p)) {
  478.       if (mkdir(p)) {
  479.         chdir(current_path);
  480.         _dos_setdrive(current_drive, &i);
  481.         return -1;
  482.       }
  483.       chdir(p);
  484.     }
  485.   }
  486.   chdir(current_path);
  487.   if (flp)
  488.     free(flp);
  489.   return 0;
  490. }
  491.  
  492. void rename_pend(char *dir, char *file)
  493. {
  494.   char s[121], s1[121], s2[121];
  495.   int i;
  496.  
  497.   sprintf(s, "%s%s", dir, file);
  498.   if (atoi(file + 1))
  499.     strcpy(s2, "P1-");
  500.   else
  501.     strcpy(s2, "P0-");
  502.   for (i = 0; i < 1000; i++) {
  503.     sprintf(s1, "%s%s%u.NET", dir, s2, i);
  504.     if (!rename(s, s1) || (errno != EACCES))
  505.       break;
  506.   }
  507. }
  508.  
  509. int process_mail(void)
  510. {
  511.   char s[121];
  512.   int f1, i, i1, i2, done, ok;
  513.   struct ffblk ff;
  514.  
  515.   sprintf(s, "%s\\FLINK.EXE", maindir);
  516.   if (exist(s))
  517.     do_spawn(s);
  518.   sprintf(s, "%s\\LINKER.EXE", maindir);
  519.   if (exist(s))
  520.     do_spawn(s);
  521.   done = 0;
  522.   for (i2 = 0; i2 < 2; i2++) {
  523.     for (i = 0; i < net_num_max; i++) {
  524.       set_net_num(i);
  525.       ok = 0;
  526.       fprintf(stderr, "\r ■ Cleaning up pending packets : %-20s", net_name);
  527.       for (i1 = 0; i1 < ninst; i1++) {
  528.         sprintf(s, "%sP*.%3.3d", net_data, i1);
  529.         f1 = findfirst(s, &ff, 0);
  530.         while (f1 == 0) {
  531.           rename_pend(net_data, ff.ff_name);
  532.           f1 = findnext(&ff);
  533.           ok = 1;
  534.         }
  535.       }
  536.       if (!ok) {
  537.         sprintf(s, "%sP*.NET", net_data);
  538.         ok = (findfirst(s, &ff, 0) == 0);
  539.       }
  540.       if (ok) {
  541.         sprintf(s, "NETWORK1 .%d", net_num);
  542.         do_spawn(s);
  543.         done = 1;
  544.       }
  545.       ok = 0;
  546.       sprintf(s, "%sLOCAL.NET", net_data);
  547.       ok = (findfirst(s, &ff, 0) == 0);
  548.       if (ok) {
  549.         fprintf(stderr, "\n ■ Processing packets in %s...\n", net_name);
  550.         sprintf(s, "NETWORK2 .%d", net_num);
  551.         do_spawn(s);
  552.         done = 1;
  553.       } else {
  554.         fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%-20s", "Done!");
  555.       }
  556.     }
  557.   }
  558.   return done;
  559. }
  560.  
  561. int valid_system(unsigned int ts)
  562. {
  563.   int i;
  564.  
  565.   for (i = 0; i < num_sys_list; i++) {
  566.     if (netsys[i].sysnum == ts) {
  567.       if (netsys[i].numhops == 1)
  568.         return (1);
  569.       else
  570.         return (0);
  571.     }
  572.   }
  573.   return (0);
  574. }
  575.  
  576. void good_addr(char *address, unsigned short sn)
  577. {
  578.   char *ss, fn[101], s[81];
  579.   unsigned short node;
  580.   int curfile;
  581.   FILE *fp;
  582.  
  583.  
  584.   curfile = 1;
  585.   address[0] = 0;
  586.   do {
  587.     sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  588.     fp = fsh_open(fn, "rt");
  589.     if (!fp)
  590.       curfile = -1;
  591.     while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
  592.       if (s[0] != '@')
  593.         continue;
  594.       ss = strtok(s, " \t\r");
  595.       node = atoi(&ss[1]);
  596.       if (node == sn) {
  597.         ss = strtok(NULL, " \t\r");
  598.         trimstr1(ss);
  599.         strcpy(address, ss);
  600.         curfile = -1;
  601.       }
  602.     }
  603.     fclose(fp);
  604.     ++curfile;
  605.   } while (curfile > 0);
  606.   if (!address[0])
  607.     return;
  608.   sprintf(fn, "%sADDRESS.0", net_data);
  609.   fp = fsh_open(fn, "rt");
  610.   if (!fp)
  611.     return;
  612.   while (fgets(s, 80, fp) != NULL) {
  613.     if (s[0] != '@')
  614.       continue;
  615.     ss = strtok(s, " \t\r");
  616.     node = atoi(&ss[1]);
  617.     if (node == sn) {
  618.       do {
  619.         ss = strtok(NULL, " \t\r");
  620.         switch (ss[0]) {
  621.           case '-':
  622.             address[0] = 0;
  623.             break;
  624.         }
  625.       } while (ss);
  626.     }
  627.   }
  628.   fclose(fp);
  629. }
  630.  
  631. int copyfile(char *input, char *output)
  632. {
  633.   int f1, f2, i;
  634.   char *b;
  635.   struct ftime ft;
  636.  
  637.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  638.     if ((b = (char *) malloc(16400)) == NULL)
  639.       return 0;
  640.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  641.     if (!f1) {
  642.       free(b);
  643.       b = NULL;
  644.       return 0;
  645.     }
  646.     getftime(f1, &ft);
  647.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  648.     if (!f2) {
  649.       free(b);
  650.       b = NULL;
  651.       sh_close(f1);
  652.       return 0;
  653.     }
  654.     i = read(f1, (void *) b, 16384);
  655.     while (i > 0) {
  656.       sh_write(f2, (void *) b, i);
  657.       i = read(f1, (void *) b, 16384);
  658.     }
  659.     f1 = sh_close(f1);
  660.     setftime(f2, &ft);
  661.     f2 = sh_close(f2);
  662.     free(b);
  663.     b = NULL;
  664.   }
  665.   return 1;
  666. }
  667.  
  668. int uu(char *fn, char *pktname, char *dest)
  669. {
  670.   int ok;
  671.   char s[121], s1[121], s2[81];
  672.   FILE *fp;
  673.  
  674.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  675.   if ((fp = fsh_open(s, "wt")) == NULL) {
  676.     fprintf(stderr, "\n ■ Unable to open %s for write operations!", s);
  677.     exit(EXIT_FAILURE);
  678.   } else {
  679.     sprintf(s2, "from: %s@%s\n", FWDNAME, FWDDOM);
  680.     fprintf(fp, s2);
  681.     sprintf(s2, "to: %s\n", dest);
  682.     fprintf(fp, s2);
  683.     sprintf(s2, "subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
  684.     fprintf(fp, s2);
  685.   }
  686.   fclose(fp);
  687.   sprintf(s1, "%s\\UU -encode %s %s", maindir, fn, s);
  688.   ok = do_spawn(s1);
  689.   return ok;
  690. }
  691.  
  692. int uu_packets(void)
  693. {
  694.   char fn[121], pktname[21], s[121], s1[121], s2[121], s3[121], destaddr[101], *ss, temp[121];
  695.   int found, sz, f;
  696.   long fpos;
  697.   unsigned short node;
  698.   FILE *fp;
  699.  
  700.   sprintf(s, "%sBBSDATA.NET", net_data);
  701.   f = sh_open1(s, O_RDONLY | O_BINARY);
  702.   num_sys_list = 0;
  703.   if (f > 0) {
  704.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  705.     if ((netsys = (net_system_list_rec *) malloc((num_sys_list + 2) *
  706.                                     sizeof(net_system_list_rec))) == NULL) {
  707.       fprintf(stderr, "\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  708.               (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  709.       sh_close(f);
  710.       return 0;
  711.     }
  712.     sh_lseek(f, 0L, SEEK_SET);
  713.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  714.     sh_close(f);
  715.   } else
  716.     return 0;
  717.   sprintf(fn, "%sADDRESS.NET", net_data);
  718.   fp = fsh_open(fn, "rt");
  719.   if (!fp) {
  720.     free(netsys);
  721.     return 0;
  722.   }
  723.   found = 0;
  724.   while (fgets(s, 80, fp) != NULL) {
  725.     node = 0;
  726.     if (s[0] != '@')
  727.       continue;
  728.     ss = strtok(s, " ");
  729.     node = atoi(&ss[1]);
  730.     if ((valid_system(node)) && (node != 32767)) {
  731.       sprintf(s1, "%sS%hd.NET", net_data, node);
  732.       if (exist(s1))
  733.         sz = 0;
  734.       else {
  735.         sprintf(s1, "%sZ%hd.NET", net_data, node);
  736.         if (exist(s1))
  737.           sz = 1;
  738.         else
  739.           continue;
  740.       }
  741.       do {
  742.         sprintf(pktname, "%lx", time(NULL));
  743.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  744.       } while (exist(temp));
  745.       good_addr(destaddr, node);
  746.       backline();
  747.       fprintf(stderr, "\r ■ Encoding %s%hd.NET as %s.UUE -",
  748.               sz ? "Z" : "S", node, strupr(pktname));
  749.       fpos = ftell(fp);
  750.       fclose(fp);
  751.       if ((uu(s1, pktname, destaddr)) == EXIT_FAILURE) {
  752.         fprintf(stderr, "\n ■ Error creating %sMQUEUE\\%s.UUE", net_data, pktname);
  753.         free(netsys);
  754.         exit(EXIT_FAILURE);
  755.       } else {
  756.         found = 1;
  757.         if (KEEPSENT) {
  758.           sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  759.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  760.           if (!copyfile(s3, s2))
  761.             fprintf(stderr, "\n ■ Error moving %s%hd.NET", sz ? "Z" : "S", node);
  762.         }
  763.         unlink(s1);
  764.       }
  765.       fp = fsh_open(fn, "rt");
  766.       fseek(fp, fpos, 0);
  767.     } else {
  768.       continue;
  769.     }
  770.     ss = strtok(NULL, "\r");
  771.     ss = NULL;
  772.   }
  773.   if (netsys)
  774.     free(netsys);
  775.   fclose(fp);
  776.   return found;
  777. }
  778.  
  779. int purge_sent(void)
  780. {
  781.   char s[121];
  782.   int f1, howmany = 0;
  783.   long age;
  784.   struct ffblk ff;
  785.   struct stat fileinfo;
  786.  
  787.   sprintf(s, "%sSENT\\*.*", net_data);
  788.   f1 = findfirst(s, &ff, 0);
  789.   while (f1 == 0) {
  790.     sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
  791.     if (stat(s, &fileinfo) == 0) {
  792.       age = (time(NULL) - fileinfo.st_atime);
  793.       if (age > (86400L * KEEPSENT)) {
  794.         ++howmany;
  795.         unlink(s);
  796.       }
  797.     }
  798.     f1 = findnext(&ff);
  799.   }
  800.   return howmany;
  801. }
  802.  
  803. /****************************************************************************/
  804.  
  805. int parse_net_ini(void)
  806. {
  807.   char cursect;
  808.   char line[121], *ss;
  809.   FILE *fp;
  810.  
  811.   fp = fsh_open("NET.INI", "rt");
  812.   if (!fp)
  813.     return (0);
  814.   while (fgets(line, 80, fp)) {
  815.     stripspace(line);
  816.     ss = NULL;
  817.     ss = strtok(line, "=");
  818.     if (ss)
  819.       ss = strtok(NULL, "\n");
  820.     /* fprintf(stderr, "\nCurrent : %s\n", line); */
  821.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  822.       continue;
  823.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  824.         (strnicmp(line, "[PPPNET]", 8) == 0)) {
  825.       cursect = INI_NETWORK;
  826.       ini_section |= INI_NETWORK;
  827.       continue;
  828.     }
  829.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  830.       cursect = INI_GENERAL;
  831.       ini_section |= INI_GENERAL;
  832.       continue;
  833.     }
  834.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  835.       cursect = INI_NEWS;
  836.       ini_section |= INI_NEWS;
  837.       continue;
  838.     }
  839.     if (cursect & INI_NETWORK) {
  840.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  841.         if (ss)
  842.           strcpy(SMTPHOST, ss);
  843.         continue;
  844.       }
  845.       if (strnicmp(line, "POPHOST", 7) == 0) {
  846.         if (ss)
  847.           strcpy(POPHOST, ss);
  848.         continue;
  849.       }
  850.       if (strnicmp(line, "POPNAME", 7) == 0) {
  851.         if (ss)
  852.           strcpy(POPNAME, ss);
  853.         continue;
  854.       }
  855.       if (strnicmp(line, "POPPASS", 7) == 0) {
  856.         if (ss)
  857.           strcpy(POPPASS, ss);
  858.         continue;
  859.       }
  860.     }
  861.     if (cursect & INI_GENERAL) {
  862.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  863.         if (atoi(ss))
  864.           TIMEOUT = atoi(ss);
  865.         continue;
  866.       }
  867.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  868.         if (atoi(ss))
  869.           SOCK_DELAY = atoi(ss);
  870.         continue;
  871.       }
  872.       if (strnicmp(line, "SOCK_INACTIVE", 13) == 0) {
  873.         if (atoi(ss))
  874.           SOCK_INACTIVE = atoi(ss);
  875.         continue;
  876.       }
  877.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  878.         if (atoi(ss))
  879.           KEEPSENT = atoi(ss);
  880.         continue;
  881.       }
  882.       if (strnicmp(line, "PURGE", 5) == 0) {
  883.         if (toupper(ss[0]) == 'N')
  884.           PURGE = 0;
  885.         continue;
  886.       }
  887.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  888.         if (toupper(ss[0]) == 'N')
  889.           ALLMAIL = 0;
  890.         continue;
  891.       }
  892.       if (strnicmp(line, "ONECALL", 7) == 0) {
  893.         if (toupper(ss[0]) == 'Y')
  894.           ONECALL = 1;
  895.         continue;
  896.       }
  897.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  898.         if (toupper(ss[0]) == 'Y')
  899.           MOREINFO = 1;
  900.         continue;
  901.       }
  902.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  903.         if (toupper(ss[0]) == 'Y')
  904.           CLEANUP = 1;
  905.         continue;
  906.       }
  907.       if (strnicmp(line, "IPADDR", 6) == 0) {
  908.         if ((ss) && (ss[0] != '0'))
  909.           strcpy(IPADDR, ss);
  910.         continue;
  911.       }
  912.       if (strnicmp(line, "NETMASK", 7) == 0) {
  913.         if (ss)
  914.           strcpy(NETMASK, ss);
  915.         continue;
  916.       }
  917.       if (strnicmp(line, "DNS", 3) == 0) {
  918.         if (ss)
  919.           strcpy(DNS, ss);
  920.         continue;
  921.       }
  922.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  923.         if (ss)
  924.           strcpy(DOMAIN, ss);
  925.         continue;
  926.       }
  927.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  928.         if (ss)
  929.           strcpy(FWDNAME, ss);
  930.         continue;
  931.       }
  932.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  933.         if (ss)
  934.           strcpy(FWDDOM, ss);
  935.         continue;
  936.       }
  937.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  938.         if ((ss) && (ss[0] != '0'))
  939.           strcpy(GATEWAY, ss);
  940.         continue;
  941.       }
  942.     }
  943.     if (cursect & INI_NEWS) {
  944.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  945.         if (ss)
  946.           strcpy(NEWSHOST, ss);
  947.         continue;
  948.       }
  949.     }
  950.   }
  951.   if (!FWDNAME[0])
  952.     strcpy(FWDNAME, POPNAME);
  953.   if (!FWDDOM[0])
  954.     strcpy(FWDDOM, DOMAIN);
  955.   fclose(fp);
  956.   return (1);
  957. }
  958.  
  959. int write_contact(unsigned short sy2, unsigned long sb, unsigned long rb, int sent, int news)
  960. {
  961.   char s[101], buf[81];
  962.   int i, i1, f;
  963.   long cur_time, l;
  964.   unsigned short sy;
  965.   FILE *fp;
  966.  
  967.   sprintf(s, "%sCONTACT.NET", net_data);
  968.   f = sh_open1(s, O_RDONLY | O_BINARY);
  969.   if (f >= 0) {
  970.     l = filelength(f);
  971.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  972.     if ((netcfg.ncn = (net_contact_rec *) malloc((netcfg.num_ncn + 2) *
  973.                                         sizeof(net_contact_rec))) == NULL) {
  974.       fprintf(stderr, "\n ■ Unable to allocate %d bytes of memory to update CONTACT.NET",
  975.               (int) (netcfg.num_ncn + 2) * sizeof(net_contact_rec));
  976.       sh_close(f);
  977.       return 1;
  978.     }
  979.     sh_lseek(f, 0L, SEEK_SET);
  980.     sh_read(f, (void *) netcfg.ncn,
  981.             netcfg.num_ncn * sizeof(net_contact_rec));
  982.     sh_close(f);
  983.   }
  984.   sprintf(s, "%sCALLOUT.NET", net_data);
  985.   fp = fsh_open(s, "rt");
  986.   if (!fp) {
  987.     fprintf(stderr, "\n ■ Unable to access %sCALLOUT.NET", net_data);
  988.     if (netcfg.ncn)
  989.       free(netcfg.ncn);
  990.     return 1;
  991.   }
  992.   while (fgets(buf, 80, fp) != NULL) {
  993.     if ((buf[0] != '@') || (strchr(buf, '_') == NULL))
  994.       continue;
  995.     sy = atoi(&buf[1]);
  996.     if ((news) && (sy != 32767))
  997.       continue;
  998.     else {
  999.       if ((!news) && (sy == 32767))
  1000.         continue;
  1001.     }
  1002.     for (i = 0; i < netcfg.num_ncn; i++)
  1003.       if (netcfg.ncn[i].systemnumber == sy)
  1004.         i1 = i;
  1005.     time(&cur_time);
  1006.     netcfg.ncn[i1].lasttry = cur_time;
  1007.     if (!sent) {
  1008.       netcfg.ncn[i1].numfails++;
  1009.     } else {
  1010.       ++netcfg.ncn[i1].numcontacts;
  1011.       if (!netcfg.ncn[i1].firstcontact)
  1012.         netcfg.ncn[i1].firstcontact = cur_time;
  1013.       netcfg.ncn[i1].lastcontact = cur_time;
  1014.       netcfg.ncn[i1].lastcontactsent = cur_time;
  1015.       if (sy == sy2) {
  1016.         netcfg.ncn[i1].bytes_sent += sb;
  1017.         if (rb)
  1018.           netcfg.ncn[i1].bytes_received += rb;
  1019.       }
  1020.       netcfg.ncn[i1].bytes_waiting = 0L;
  1021.       sprintf(s, "%sS%hd.net", net_data, sy);
  1022.       if (!exist(s))
  1023.         sprintf(s, "%sZ%hd.net", net_data, sy);
  1024.       f = sh_open1(s, O_RDONLY | O_BINARY);
  1025.       if (f > 0) {
  1026.         netcfg.ncn[i1].bytes_waiting += filelength(f);
  1027.         close(f);
  1028.       }
  1029.     }
  1030.  
  1031.     sprintf(s, "%sCONTACT.NET", net_data);
  1032.     f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  1033.     if (f > 0) {
  1034.       sh_lseek(f, 0L, SEEK_SET);
  1035.       sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn *
  1036.                sizeof(net_contact_rec));
  1037.       sh_close(f);
  1038.     }
  1039.   }
  1040.   if (netcfg.ncn)
  1041.     free(netcfg.ncn);
  1042.   fclose(fp);
  1043.   return 0;
  1044. }
  1045.  
  1046. int count_lines(char *s)
  1047. {
  1048.   FILE *fp;
  1049.   char fn[121];
  1050.   unsigned int nl = 0;
  1051.   const int NEWLINE = '\n';
  1052.   int c;
  1053.  
  1054.   strcpy(fn, s);
  1055.   fp = fsh_open(fn, "rt");
  1056.   if (fp == NULL) {
  1057.     printf("\n ■ Cannot open %s", fn);
  1058.     return 0;
  1059.   }
  1060.   while ((c = getc(fp)) != EOF) {
  1061.     if (c == NEWLINE)
  1062.       ++nl;
  1063.   }
  1064.   fclose(fp);
  1065.   return nl;
  1066. }
  1067.  
  1068. typedef struct {
  1069.   char line[81];
  1070. } nlines;
  1071.  
  1072. nlines *NETLOG;
  1073.  
  1074. int write_netlog(int sn, long sent, long recd, char *tmused)
  1075. {
  1076.   FILE *fp;
  1077.   int i = 0;
  1078.   unsigned int lines;
  1079.   char s[81], s1[81], s2[81], fn[121];
  1080.   struct tm *time_now;
  1081.   time_t some;
  1082.  
  1083.   sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
  1084.   lines = 0;
  1085.   lines = count_lines(fn);
  1086.   if ((NETLOG = ((nlines *) malloc((lines + 2) * 81))) == NULL) {
  1087.     fprintf(stderr, "\n ■ Unable to allocate %d bytes for NET.LOG entry",
  1088.             (lines + 2) * 81);
  1089.     return 1;
  1090.   }
  1091.   fp = fsh_open(fn, "r");
  1092.   if (!fp)
  1093.     return 1;
  1094.   while (fgets(s, 80, fp)) {
  1095.     strtok(s, "\n");
  1096.     strcpy(NETLOG[i++].line, s);
  1097.   }
  1098.   fclose(fp);
  1099.   time(&some);
  1100.   time_now = localtime(&some);
  1101.   strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
  1102.   if ((sent) || (recd)) {
  1103.     if ((recd) && (!sent))
  1104.       sprintf(s2, "       , R:%4ldk,", recd);
  1105.     else {
  1106.       if ((recd) && (sent))
  1107.         sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
  1108.       else
  1109.         sprintf(s2, "S:%4ldk,         ", sent);
  1110.     }
  1111.   } else
  1112.     strcpy(s2, "                 ");
  1113.   fp = fsh_open(fn, "wt+");
  1114.   fprintf(fp, "%s To %5d, %s          %4s min  %s\n", s1, sn, s2,
  1115.           tmused, net_name);
  1116.   for (i = 0; i < lines; i++)
  1117.     fprintf(fp, "%s\n", NETLOG[i].line);
  1118.   if (NETLOG)
  1119.     free(NETLOG);
  1120.   NETLOG = NULL;
  1121.   fclose(fp);
  1122.   return 0;
  1123. }
  1124.  
  1125. void read_networks(void)
  1126. {
  1127.   int f;
  1128.   char s[121];
  1129.  
  1130.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1131.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1132.   net_num_max = 0;
  1133.   if (f > 0) {
  1134.     net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
  1135.     sh_close(f);
  1136.   }
  1137. }
  1138.  
  1139. void init(void)
  1140. {
  1141.   char s[81], s1[81], *ss;
  1142.   int i, i1, dv, f;
  1143.   struct tm *time_now;
  1144.   time_t some;
  1145.  
  1146.   fprintf(stderr, "\n%s\n%s\n\n", version, author);
  1147.   get_dir(maindir, 0);
  1148.   ss = getenv("WWIV_INSTANCE");
  1149.   if (ss) {
  1150.     instance = atoi(ss);
  1151.     if ((instance <= 0) || (instance > 999)) {
  1152.       fprintf(stderr, "\n ■ WWIV_INSTANCE can only be 1..999!");
  1153.       instance = 1;
  1154.     }
  1155.   } else {
  1156.     instance = 1;
  1157.   }
  1158.   if (get_nb_version())
  1159.     multitasker = 8;
  1160.   else
  1161.     detect_multitask();
  1162.   switch (multitasker) {
  1163.     case 1:
  1164.       dv = get_dv_version();
  1165.       sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
  1166.       break;
  1167.     case 2:
  1168.       dv = get_win_version();
  1169.       if (dv == 4)
  1170.         strcpy(s1, "Windows 95");
  1171.       else
  1172.         sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
  1173.       break;
  1174.     case 3:
  1175.       dv = get_dv_version();
  1176.       sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
  1177.       break;
  1178.     case 4:
  1179.     case 5:
  1180.     case 6:
  1181.     case 7:
  1182.       if ((_osmajor / 10 == 2) && (_osminor >= 30))
  1183.         strcpy(s1, "OS/2 Warp");
  1184.       else
  1185.         sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
  1186.       break;
  1187.     case 8:
  1188.       sprintf(s1, "NETBIOS network");
  1189.       multitasker = 1;
  1190.       break;
  1191.     default:
  1192.       strcpy(s1, "DOS");
  1193.       break;
  1194.   }
  1195.   strcpy(s, "CONFIG.DAT");
  1196.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1197.   if (f < 0) {
  1198.     fprintf(stderr, "\n ■ %s NOT FOUND.", s);
  1199.     return;
  1200.   }
  1201.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1202.   sh_close(f);
  1203.   fprintf(stderr, " ■ Running under %s on instance %d ", s1, instance);
  1204.   time(&some);
  1205.   time_now = localtime(&some);
  1206.   strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1207.   printf(s);
  1208.   strcpy(s, "CONFIG.OVR");
  1209.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1210.   if (f < 0) {
  1211.     fprintf(stderr, "\n ■ %s NOT FOUND.", s);
  1212.     return;
  1213.   }
  1214.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1215.   read(f, &syscfgovr, sizeof(configoverrec));
  1216.   f = sh_close(f);
  1217.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1218.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1219.   if (f < 0) {
  1220.     fprintf(stderr, "\n ■ %s NOT FOUND.", s);
  1221.     return;
  1222.   }
  1223.   ninst = (int) ((filelength(f) / (long) sizeof(instancerec)));
  1224.   f = sh_close(f);
  1225.   read_networks();
  1226.   i = i1 = 0;
  1227.   while (environ[i] != NULL) {
  1228.     xenviron[i1++] = environ[i];
  1229.     ++i;
  1230.   }
  1231.   xenviron[i1] = NULL;
  1232. }
  1233.  
  1234. long getfctime(char *s)
  1235. {
  1236.   struct stat statbuf;
  1237.  
  1238.   if (stat(s, &statbuf) < 0)
  1239.     return (0L);
  1240.   else
  1241.     return (statbuf.st_atime);
  1242. }
  1243.  
  1244. int process_bbsdata(void)
  1245. {
  1246.   char s[101];
  1247.   unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
  1248.   int tf, n, net3;
  1249.  
  1250.   net3 = 0;
  1251.   sprintf(s, "%sBBSLIST.NET", net_data);
  1252.   bbslist_ctime = getfctime(s);
  1253.   sprintf(s, "%sCONNECT.NET", net_data);
  1254.   connect_ctime = getfctime(s);
  1255.   sprintf(s, "%sCALLOUT.NET", net_data);
  1256.   callout_ctime = getfctime(s);
  1257.   sprintf(s, "%sBBSDATA.NET", net_data);
  1258.   bbsdata_ctime = getfctime(s);
  1259.   sprintf(s, "%sBBSLIST.UPD", net_data);
  1260.   bbslist_ctime = getfctime(s);
  1261.   sprintf(s, "%sCONNECT.UPD", net_data);
  1262.   connect_ctime = getfctime(s);
  1263.  
  1264.   n = 0;
  1265.   tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
  1266.   if (tf)
  1267.     n = 1;
  1268.   tf = (tf || (callout_ctime > bbsdata_ctime));
  1269.   if (tf) {
  1270.     sprintf(s, "NETWORK3 .%d", netnum);
  1271.     if (n) {
  1272.       sprintf(s, "NETWORK3 .%d Y", netnum);
  1273.       net3 = 1;
  1274.     }
  1275.     do_spawn(s);
  1276.   }
  1277.   return (net3);
  1278. }
  1279.  
  1280. void do_it(char *cl)
  1281. {
  1282.   int i, i1, l;
  1283.   char *s, *ss[30];
  1284.  
  1285.   s = strdup(cl);
  1286.   ss[0] = s;
  1287.   i = 1;
  1288.   l = strlen(s);
  1289.   for (i1 = 1; i1 < l; i1++)
  1290.     if (s[i1] == 32) {
  1291.       s[i1] = 0;
  1292.       ss[i++] = &(s[i1 + 1]);
  1293.     }
  1294.   ss[i] = NULL;
  1295.   execvpe(ss[0], ss, xenviron);
  1296. }
  1297.  
  1298. int create_wattcp_cfg(void)
  1299. {
  1300.   char s[MAXPATH], s1[41];
  1301.   FILE *fp;
  1302.  
  1303.   sprintf(s, "%s\\WATTCP.CFG", maindir);
  1304.   if ((fp = fsh_open(s, "wt")) == NULL) {
  1305.     fprintf(stderr, "\n ■ Can't open %s for output!", s);
  1306.     return 1;
  1307.   }
  1308.   sprintf(s, "my_ip=%s\n", IPADDR);
  1309.   fprintf(fp, s);
  1310.   fprintf(fp, "netmask=%s\n", NETMASK);
  1311.   fprintf(fp, "nameserver=%s\n", DNS);
  1312.   if (GATEWAY[0] == 0) {
  1313.     strcpy(s1, IPADDR);
  1314.     while (LAST(s1) != '.')
  1315.       LAST(s1) = 0;
  1316.     strcat(s1, "1");
  1317.     strcpy(GATEWAY, s1);
  1318.   }
  1319.   sprintf(s, "gateway=%s\n", GATEWAY);
  1320.   fprintf(fp, s);
  1321.   fprintf(fp, "domainslist=\"%s\"\n", DOMAIN);
  1322.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1323.   fprintf(fp, "sockdelay=\"%d\"\n", SOCK_DELAY);
  1324.   fprintf(fp, "sockinactive=\"%d\"\n", SOCK_INACTIVE);
  1325.   fclose(fp);
  1326.   return 0;
  1327. }
  1328.  
  1329. int check_for_lsl(void)
  1330. {
  1331.   union REGS r;
  1332.   struct SREGS s;
  1333.   char *intstr;
  1334.  
  1335.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1336.     r.h.al = 0;
  1337.     int86x(0x2f, &r, &r, &s);
  1338.     if (r.h.al == 0xff) {
  1339.       intstr = (char *) MK_FP(s.es, r.x.si);
  1340.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1341.         return 1;
  1342.     }
  1343.   }
  1344.   return 0;
  1345. }
  1346.  
  1347. void klos_ppp(void)
  1348. {
  1349.   char s[121], *ss;
  1350.   int i;
  1351.   FILE *fp;
  1352.  
  1353.   lsl_loaded = check_for_lsl();
  1354.   if (!lsl_loaded) {
  1355.     sprintf(s, "%s\\LSL.COM", maindir);
  1356.     if (exist(s)) {
  1357.       fprintf(stderr, "\n ■ Loading Link Support Layer and ");
  1358.       do_spawn(s);
  1359.     } else {
  1360.       fprintf(stderr, "\n ■ LSL.COM not in BBS main directory!");
  1361.       exit(EXIT_FAILURE);
  1362.     }
  1363.   } else
  1364.     fprintf(stderr, "\n ■ LSL already in memory - loading ");
  1365.   sprintf(s, "%s\\PPP.EXE", maindir);
  1366.   if (exist(s)) {
  1367.     fprintf(stderr, "PPP packet driver... ");
  1368.     do_spawn(s);
  1369.   } else {
  1370.     fprintf(stderr, "\n ■ KLOS PPP.EXE not in BBS main directory!");
  1371.     exit(EXIT_FAILURE);
  1372.   }
  1373.   sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1374.   if (exist(s)) {
  1375.     fprintf(stderr, "\n ■ Dialing %s and waiting %d seconds for connection... ", DOMAIN, TIMEOUT);
  1376.     sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1377.     i = do_spawn(s);
  1378.     switch (i) {
  1379.       case 0:
  1380.         fprintf(stderr, " connected!");
  1381.         break;
  1382.       case 1:
  1383.         fprintf(stderr, "\n ■ Unable to establish connection... aborting");
  1384.         sprintf(s, "%s\\PPP U", maindir);
  1385.         do_spawn(s);
  1386.         if (!lsl_loaded) {
  1387.           sprintf(s, "%s\\LSL U", maindir);
  1388.           do_spawn(s);
  1389.         }
  1390.         exit(EXIT_FAILURE);
  1391.       case 2:
  1392.         fprintf(stderr, "\n ■ Unable to find PPP layer... aborting");
  1393.         sprintf(s, "%s\\PPP U", maindir);
  1394.         do_spawn(s);
  1395.         if (!lsl_loaded) {
  1396.           sprintf(s, "%s\\LSL U", maindir);
  1397.           do_spawn(s);
  1398.         }
  1399.         exit(EXIT_FAILURE);
  1400.       default:
  1401.         fprintf(stderr, "\n ■ Unknown PPPState Error #%d... aborting", i);
  1402.         sprintf(s, "%s\\PPP U", maindir);
  1403.         do_spawn(s);
  1404.         if (!lsl_loaded) {
  1405.           sprintf(s, "%s\\LSL U", maindir);
  1406.           do_spawn(s);
  1407.         }
  1408.         exit(EXIT_FAILURE);
  1409.     }
  1410.   } else {
  1411.     fprintf(stderr, "\n ■ PPPSTATE.EXE not in BBS main directory!");
  1412.     exit(EXIT_FAILURE);
  1413.   }
  1414.   sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1415.   if (exist(s)) {
  1416.     do_spawn(s);
  1417.   } else {
  1418.     fprintf(stderr, "\n ■ KLOS PPPWAT.EXE not in BBS main directory!");
  1419.     exit(EXIT_FAILURE);
  1420.   }
  1421.   if (!IPADDR[0]) {
  1422.     fp = fsh_open("WATTCP.CFG", "rt");
  1423.     if (fp) {
  1424.       while (fgets(s, 80, fp) != NULL) {
  1425.         if (strnicmp(s, "my_ip", 5) == 0) {
  1426.           ss = strtok(s, "=");
  1427.           ss = strtok(NULL, "\r");
  1428.           trimstr1(ss);
  1429.           strcpy(IPADDR, ss);
  1430.           break;
  1431.         }
  1432.       }
  1433.       fclose(fp);
  1434.     }
  1435.   }
  1436.   if (IPADDR) {
  1437.     create_wattcp_cfg();
  1438.     fprintf(stderr, "\n ■ IP address is %s... ", IPADDR);
  1439.   } else {
  1440.     fprintf(stderr, "\n ■ Could not find IP Address for WATTCP.CFG... aborting!");
  1441.     unload_klos();
  1442.     exit(EXIT_FAILURE);
  1443.   }
  1444.   sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1445.   if (exist(s)) {
  1446.     do_spawn(s);
  1447.   } else {
  1448.     fprintf(stderr, "\n ■ KLOS PPPWAT.EXE not in BBS main directory!");
  1449.     exit(EXIT_FAILURE);
  1450.   }
  1451.   fprintf(stderr, "establishing socket     ");
  1452.   for (i = 5; i >= 0; i--) {
  1453.     fprintf(stderr, "\b\b\b\b%d...", i);
  1454.     delay(1000);
  1455.   }
  1456.   fprintf(stderr, "\b\b\b\b- ready!");
  1457. }
  1458.  
  1459. double freek(int dr)
  1460. {
  1461.   float d;
  1462.   struct dfree df;
  1463.  
  1464.   getdfree(dr, &df);
  1465.   d = (float) df.df_avail;
  1466.   d *= ((float) df.df_bsec);
  1467.   d *= ((float) df.df_sclus);
  1468.   d /= 1024.0;
  1469.   if (df.df_sclus == 0xffff)
  1470.     d = -1.0;
  1471.   return (d);
  1472. }
  1473.  
  1474. int main(int argc, char *argv[])
  1475. {
  1476.   int i, ok, news, totf, send, f1;
  1477.   unsigned short sy;
  1478.   double dspace;
  1479.   char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
  1480.   char ttotal[21];
  1481.   clock_t starttime, mailtime, newstime;
  1482.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1483.   FILE *fp;
  1484.   struct ffblk ff;
  1485.  
  1486.   init();
  1487.   news = 0;
  1488.   ss = argv[argc - 1];
  1489.   ok = 0;
  1490.   if (_fstrstr((char *) ss, ".") != NULL) {
  1491.     if (atoi(&ss[1]) < net_num_max) {
  1492.       netnum = atoi(&ss[1]);
  1493.       ok = 1;
  1494.     }
  1495.   } else {
  1496.     ss = (getenv("WWIV_NET"));
  1497.     netnum = atoi(ss);
  1498.     if (netnum < net_num_max)
  1499.       ok = 1;
  1500.   }
  1501.   if (!ok) {
  1502.     strcpy(s, "WWIV_NET.DAT");
  1503.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1504.       fgets(s, 3, fp);
  1505.       netnum = atoi(s);
  1506.       fclose(fp);
  1507.       if (netnum < net_num_max)
  1508.         ok = 1;
  1509.     }
  1510.   }
  1511.   ss = argv[1];
  1512.   if (strncmpi(ss, "/N", 2))
  1513.     ok = 0;
  1514.   if (ok) {
  1515.     SMTPHOST[0] = 0;
  1516.     POPHOST[0] = 0;
  1517.     NEWSHOST[0] = 0;
  1518.     POPNAME[0] = 0;
  1519.     POPPASS[0] = 0;
  1520.     IPADDR[0] = 0;
  1521.     NETMASK[0] = 0;
  1522.     DNS[0] = 0;
  1523.     DOMAIN[0] = 0;
  1524.     GATEWAY[0] = 0;
  1525.     FWDNAME[0] = 0;
  1526.     FWDDOM[0] = 0;
  1527.     if (parse_net_ini()) {
  1528.       set_net_num(netnum);
  1529.       if (ini_section & INI_NETWORK) {
  1530.         if (!(ini_section & INI_GENERAL)) {
  1531.           fprintf(stderr, "\n ■ [GENERAL] tag missing from NET.INI!");
  1532.           ok = 0;
  1533.         }
  1534.       } else {
  1535.         ok = 0;
  1536.         fprintf(stderr, "\n ■ [FILENET] tag missing from NET.INI!");
  1537.       }
  1538.     } else {
  1539.       fprintf(stderr, "\n ■ Could not open file NET.INI!");
  1540.       ok = 0;
  1541.     }
  1542.   }
  1543.   if (ok) {
  1544.     fprintf(stderr, "\n ■ Available memory : %ld bytes...", coreleft());
  1545.     if (net_data[1] == ':')
  1546.       i = net_data[0];
  1547.     else
  1548.       i = maindir[0];
  1549.     i = toupper(i) - 'A' + 1;
  1550.     dspace = freek(i);
  1551.     if (dspace < 1024.0) {
  1552.       fprintf(stderr, "\n ■ Only %.1fK available on drive %c:... aborting!",
  1553.               dspace, i + '@');
  1554.       exit(EXIT_FAILURE);
  1555.     } else {
  1556.       fprintf(stderr, " disk space ");
  1557.       if (dspace < 10000.0)
  1558.         fprintf(stderr, ": %c:%.1fK", i + '@', dspace);
  1559.       else
  1560.         fprintf(stderr, ": %c:%.1fM", i + '@', dspace / 1024.0);
  1561.     }
  1562.  
  1563.     set_net_num(netnum);
  1564.     ss = argv[1];
  1565.     sy = atoi(&ss[2]);
  1566.     destaddr[0] = 0;
  1567.     if (sy != 32767)
  1568.       good_addr(destaddr, sy);
  1569.  
  1570.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1571.       fprintf(stderr, "\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1572.       ok = 0;
  1573.     } else {
  1574.       ok = 1;
  1575.       if (sy == 32767) {
  1576.         if (ini_section & INI_NEWS) {
  1577.           fprintf(stderr, "\n ■ Initiating newsgroup retrieval session...");
  1578.           news = 1;
  1579.         } else {
  1580.           fprintf(stderr, "\n ■ [NEWS] tag missing from NET.INI!");
  1581.           exit(EXIT_FAILURE);
  1582.         }
  1583.       }
  1584.     }
  1585.   }
  1586.   if (ok) {
  1587.     if (!MOREINFO)
  1588.       freopen(NULL, "w", stdout);
  1589.     if (CLEANUP)
  1590.       process_mail();
  1591.     set_net_num(netnum);
  1592.     sprintf(s, "%sSPOOL", net_data);
  1593.     if ((make_path(s)) < 0) {
  1594.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1595.       exit(EXIT_FAILURE);
  1596.     }
  1597.     sprintf(s, "%sMQUEUE", net_data);
  1598.     if ((make_path(s)) < 0) {
  1599.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1600.       exit(EXIT_FAILURE);
  1601.     }
  1602.     sprintf(s, "%sOUTBOUND", net_data);
  1603.     if ((make_path(s)) < 0) {
  1604.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1605.       exit(EXIT_FAILURE);
  1606.     }
  1607.     sprintf(s, "%sINBOUND", net_data);
  1608.     if ((make_path(s)) < 0) {
  1609.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1610.       exit(EXIT_FAILURE);
  1611.     }
  1612.     sprintf(s, "%sSENT", net_data);
  1613.     if ((make_path(s)) < 0) {
  1614.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1615.       exit(EXIT_FAILURE);
  1616.     }
  1617.     if (PURGE) {
  1618.       if ((KEEPSENT) && (sy != 32767)) {
  1619.         fprintf(stderr, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1620.                 KEEPSENT == 1 ? "" : "s");
  1621.         i = purge_sent();
  1622.         fprintf(stderr, " %d packet%s deleted.", i, i == 1 ? "" : "s");
  1623.       }
  1624.     }
  1625.     sprintf(s, "%sCHECKNET", net_data);
  1626.     if ((make_path(s)) < 0) {
  1627.       fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
  1628.       exit(EXIT_FAILURE);
  1629.     }
  1630.     send = 1;
  1631.     cd_to(maindir);
  1632.     if ((sy != 32767) || (ONECALL)) {
  1633.       fprintf(stderr, "\n ■ Preparing outbound mail for transmission...");
  1634.       if (!uu_packets()) {
  1635.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1636.         if (findfirst(s, &ff, 0) == 0) {
  1637.           fprintf(stderr, " outbound packets in MQUEUE.");
  1638.         } else {
  1639.           fprintf(stderr, " no mail or packets to send.");
  1640.           send = 0;
  1641.         }
  1642.       } else {
  1643.         backline();
  1644.         fprintf(stderr, "\r ■ All packets prepared for transmission.");
  1645.       }
  1646.     }
  1647.     sprintf(s, "%sNET%d.CFG", net_data, instance);
  1648.     if (exist(s)) {
  1649.       sprintf(s1, "%s\\NET.CFG", maindir);
  1650.       unlink(s1);
  1651.       if (!copyfile(s, s1))
  1652.         fprintf(stderr, "\n ■ Unable to copy %s to %s", s, s1);
  1653.       else
  1654.         fprintf(stderr, "\n ■ Copied %s for use as NET.CFG", strlwr(s));
  1655.     }
  1656.     sprintf(s, "%s\\EXP.EXE", maindir);
  1657.     if (!exist(s)) {
  1658.       fprintf(stderr, "\n ■ Export module EXP.EXE not found!");
  1659.     } else {
  1660.       sprintf(s, "%sS32767.NET", net_data);
  1661.       sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
  1662.       if ((exist(s)) || (exist(s1))) {
  1663.         sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1664.                 net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1665.         if (do_spawn(s))
  1666.           fprintf(stderr, "\n ■ Unknown error during export");
  1667.       } else
  1668.         fprintf(stderr, "\n ■ No inbound or outbound Internet mail or newsgroup posts to process.");
  1669.     }
  1670.  
  1671.     klos_ppp();
  1672.     starttime = clock();
  1673.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1674.  
  1675.     cd_to(maindir);
  1676.     create_wattcp_cfg();
  1677.  
  1678.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1679.  
  1680.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1681.       totf = 0;
  1682.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1683.       f1 = findfirst(temp, &ff, FA_ARCH);
  1684.       if (f1 == 0)
  1685.         fprintf(stderr, "\n");
  1686.       while (f1 == 0) {
  1687.         sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
  1688.         sprintf(s, "%s\\POP -send %s %s %s", maindir, SMTPHOST, DOMAIN, s1);
  1689.         backline();
  1690.         fprintf(stderr, "\r ■ Sending %s ", ff.ff_name);
  1691.         if (do_spawn(s) == EXIT_SUCCESS) {
  1692.           unlink(s1);
  1693.           sentbytes += ff.ff_fsize;
  1694.           ++totf;
  1695.         } else
  1696.           fprintf(stderr, "\n ■ Unsuccessful!  %s remains in MQUEUE.", ff.ff_name);
  1697.         f1 = findnext(&ff);
  1698.       }
  1699.       backline();
  1700.       fprintf(stderr, "\r ■ Outbound mail transfer completed - %d file%s, %ldK bytes.",
  1701.               totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1702.       send = 0;
  1703.     }
  1704.     if ((sy != 32767) || (ONECALL)) {
  1705.       sprintf(s, "%s\\POP -receive %s %s %s %s %d %s", maindir, POPHOST, POPNAME, POPPASS,
  1706.               temp_dir, ALLMAIL, DOMAIN);
  1707.       fprintf(stderr, "\n ■ Checking %s for inbound net packets.", POPHOST);
  1708.       sprintf(s1, "%s*.*", temp_dir);
  1709.       if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
  1710.         sprintf(temp, "%s*.*", temp_dir);
  1711.         f1 = findfirst(temp, &ff, FA_ARCH);
  1712.         i = 0;
  1713.         send = 0;
  1714.         while (f1 == 0) {
  1715.           if (strncmp(ff.ff_name, "BAD", 3) != 0) {
  1716.             recdbytes += ff.ff_fsize;
  1717.             sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1718.             sprintf(temp, "%s\\UU -decode %s %s %s", maindir, ff.ff_name,
  1719.                     temp_dir, net_data);
  1720.             if (!do_spawn(temp)) {
  1721.               send = 1;
  1722.               unlink(s1);
  1723.             }
  1724.           }
  1725.           f1 = findnext(&ff);
  1726.         }
  1727.       } else
  1728.         fprintf(stderr, "\n ■ No network packets to process");
  1729.  
  1730.       if ((send) && (CLEANUP)) {
  1731.         fprintf(stderr, "\n ■ Processing received packets... please wait.");
  1732.         process_mail();
  1733.         set_net_num(netnum);
  1734.         process_bbsdata();
  1735.       }
  1736.     }
  1737.     mailtime = clock() - starttime;
  1738.     if ((sy == 32767) || (ONECALL)) {
  1739.       starttime = clock();
  1740.       set_net_num(netnum);
  1741.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1742.       f1 = findfirst(temp, &ff, FA_ARCH);
  1743.       while (f1 == 0) {
  1744.         snewsbytes += ff.ff_fsize;
  1745.         f1 = findnext(&ff);
  1746.       }
  1747.       cd_to(maindir);
  1748.       strcpy(s1, net_data);
  1749.       if (LAST(s1) == '\\')
  1750.         LAST(s1) = 0;
  1751.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1752.       ok = 1;
  1753.       if (do_spawn(s) != EXIT_SUCCESS)
  1754.         fprintf(stderr, "\n ■ Unsuccessful news retrieval session...");
  1755.       set_net_num(netnum);
  1756.       sprintf(temp, "%sP0*.*", net_data);
  1757.       f1 = findfirst(temp, &ff, 0);
  1758.       while (f1 == 0) {
  1759.         rnewsbytes += ff.ff_fsize;
  1760.         f1 = findnext(&ff);
  1761.       }
  1762.     }
  1763.     sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1764.     if (exist(s)) {
  1765.       sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1766.               net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1767.       if (do_spawn(s))
  1768.         fprintf(stderr, "\n ■ Unknown error during export");
  1769.     }
  1770.   } else {
  1771.     fprintf(stderr, "\n");
  1772.     set_net_num(netnum);
  1773.     strcpy(s, "NETWORK0.EXE");
  1774.     for (i = 1; i < argc; i++) {
  1775.       strcat(s, " ");
  1776.       strcat(s, argv[i]);
  1777.     }
  1778.     s[strlen(s) + 1] = '\0';
  1779.     do_it(s);
  1780.     exit(EXIT_SUCCESS);
  1781.   }
  1782.   unload_klos();
  1783.   newstime = clock() - starttime;
  1784.   fprintf(stderr, "\n ■ Updating network connection records...");
  1785.   if (ONECALL) {
  1786.     recdbytes = ((recdbytes + 1023) / 1024);
  1787.     sentbytes = ((sentbytes + 1023) / 1024);
  1788.     if (mailtime)
  1789.       sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1790.     else
  1791.       strcpy(ttotal, "0.1");
  1792.     if (write_contact(sy, sentbytes, recdbytes, 1, 0))
  1793.       fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
  1794.     if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1795.       fprintf(stderr, "\n ■ Unable to access NET.LOG!");
  1796.     if (newstime)
  1797.       sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1798.     else
  1799.       strcpy(ttotal, "0.1");
  1800.     rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1801.     snewsbytes = ((snewsbytes + 1023) / 1024);
  1802.     if (write_contact(32767, snewsbytes, rnewsbytes, 1, 1))
  1803.       fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
  1804.     if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1805.       fprintf(stderr, "\n ■ Unable to access NET.LOG!");
  1806.   } else {
  1807.     if (news) {
  1808.       if (newstime)
  1809.         sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1810.       else
  1811.         strcpy(ttotal, "0.1");
  1812.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1813.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1814.       if (write_contact(32767, snewsbytes, rnewsbytes, 1, 1))
  1815.         fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
  1816.       if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1817.         fprintf(stderr, "\n ■ Unable to access NET.LOG!");
  1818.     } else {
  1819.       recdbytes = ((recdbytes + 1023) / 1024);
  1820.       sentbytes = ((sentbytes + 1023) / 1024);
  1821.       if (mailtime)
  1822.         sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1823.       else
  1824.         strcpy(ttotal, "0.1");
  1825.       if (write_contact(sy, sentbytes, recdbytes, 1, 0))
  1826.         fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
  1827.       if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1828.         fprintf(stderr, "\n ■ Unable to access NET.LOG!");
  1829.     }
  1830.   }
  1831.   cd_to(maindir);
  1832.   set_net_num(netnum);
  1833.   fprintf(stderr, "\n ■ %s completed!\n\n", version);
  1834.   return 0;
  1835. }
  1836.