home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / NODEPROC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  36KB  |  925 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                 BinkleyTerm Nodelist processing module                   */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. char far *get_size (unsigned int);
  51. int get_new_info (unsigned);
  52.  
  53. #ifdef OLDTBBSLIST
  54. int get_TBBS_info (unsigned, ADDR *);
  55. #endif
  56.  
  57. #ifdef V5_LIST
  58. int get_old_info (unsigned);
  59. #endif
  60.  
  61. static off_t  index_filesize = (off_t)  0L;
  62. static time_t index_filetime = (time_t) 0L;
  63. static char   index_filename[80];
  64.  
  65. static unsigned int idx_size = 0;                       /* number of entries  */
  66. static int extra_bytes = 0;
  67. static char *curr_domain = NULL;
  68.  
  69. void get_nodelist_name (ADDR *);
  70.  
  71. void get_nodelist_name (ADDRP opus_addr)
  72. {
  73.     int i;
  74.  
  75.     curr_domain = opus_addr->Domain;
  76.  
  77.     idx_size = 0;
  78.     extra_bytes = 0;
  79.     nodelist_base = nodelist_name;
  80.     for (i = 0; domain_name[i] != NULL; i++)
  81.         {
  82.         if (domain_name[i] == opus_addr->Domain)
  83.             {
  84.             nodelist_base = domain_nodelist[i];
  85.             if (nodelist_base == NULL)
  86.                 nodelist_base = nodelist_name;
  87.             }
  88.         }
  89. }
  90.  
  91. char far *get_size (unsigned int n)
  92. {
  93.     /* If we get this far, then we have to use a straight far pointer */
  94.     return (_fmalloc(n));
  95. }
  96.  
  97. /*---------------------------------------------------------------------------*/
  98. /* CHECKLIST                                                                 */
  99. /* See if nodelist has changed since we first tried to use it and if so,     */
  100. /* dismiss old copy and get a new one                                        */
  101. /*---------------------------------------------------------------------------*/
  102.  
  103. int checklist ()
  104. {
  105.     struct stat idxstat;
  106.     if (index_filesize == (off_t)0L)
  107.         return (0);
  108.     (void) stat (index_filename, &idxstat);    
  109.     if ((index_filesize == idxstat.st_size) && (index_filetime == idxstat.st_mtime)) 
  110.         return (0);
  111.     status_line (MSG_TXT(M_REFRESH_NODELIST));
  112.     _ffree( node_index );
  113.     node_index = (char far *) NULL;
  114.     index_filesize = (off_t)0L;
  115.     return (1);
  116. }
  117.  
  118.  
  119. /*---------------------------------------------------------------------------*/
  120. /* NODEPROC                                                                  */
  121. /* Find nodelist entry and set baud to nodelist baud for dialing out         */
  122. /*---------------------------------------------------------------------------*/
  123.  
  124. int nodeproc (char *nodeaddr)
  125. {
  126.     ADDR opus_addr;
  127.     char *c;
  128.  
  129.     c = skip_blanks (nodeaddr);                     /* get rid of the blanks  */
  130.     if (!find_address (c, &opus_addr))
  131.         {
  132.         return (0);
  133.         }
  134.     if (!nodefind (&opus_addr, 1))              /* if we can't find the node  */
  135.         return (0);                             /* go away now                */
  136.     status_line (MSG_TXT(M_PROCESSING_NODE), Full_Addr_Str (&opus_addr), newnodedes.SystemName);
  137.     if (!CARRIER)                               /* if no carrier yet,         */
  138.         {
  139.         if (autobaud)
  140.             (void) set_baud (max_baud.rate_value, 1);   /* Set to highest rate*/
  141.         else
  142.             (void) set_baud ((300 * newnodedes.BaudRate), 1);/* nodelist baud */
  143.         }
  144.     return (1);                                 /* return success to caller   */
  145. }
  146.  
  147. /*---------------------------------------------------------------------------*/
  148. /* NODEFIND                                                                  */
  149. /* Find nodelist entry for use by other routines (password, nodeproc)        */
  150. /* If found, result will be in "newnodedes".                                 */
  151. /*---------------------------------------------------------------------------*/
  152.  
  153. int nodefind (ADDRP bink_addr, int prtflag)
  154. {
  155.     int i, j, k;
  156.     int have_boss_data = 0;
  157.     int need_boss_data = 0;
  158.  
  159.     (void) checklist ();
  160.  
  161.     newnodedes.NetNumber = newnodedes.NodeNumber = found_zone = found_net = 0;
  162.  
  163.     CURRENT = DEFAULT;                          /* Set default paths, quotas  */
  164.  
  165.     if ((bink_addr->Net == boss_addr.Net) 
  166.     &&  (bink_addr->Node == boss_addr.Node) 
  167.     &&  (bink_addr->Zone == alias[0].Zone) 
  168.     &&  ((bink_addr->Domain == boss_addr.Domain) || (bink_addr->Domain == NULL)))
  169.         {
  170.         ++need_boss_data;
  171.         if (BOSSphone && strlen (BOSSphone) > 2)
  172.             ++have_boss_data;
  173.         if (BOSSpwd && strlen (BOSSpwd) > 2)
  174.             ++have_boss_data;
  175.         }
  176.  
  177.     if (!bink_addr->Zone)
  178.         {
  179.         bink_addr->Zone = alias[0].Zone;
  180.         i = (*nodefunc) (bink_addr, have_boss_data);
  181.         if (i) goto lookup_done;
  182.         }
  183.     i = (*nodefunc) (bink_addr, have_boss_data);
  184.  
  185. lookup_done:
  186.  
  187.     assumed = k = 0;                            /* Default to zone of first   */
  188.     for (j = 0; j < num_addrs; j++)
  189.         {
  190.         if ((alias[j].Point != 0) 
  191.         &&  ((alias[j].Node != newnodedes.NodeNumber) 
  192.           || (alias[j].Net != found_net) 
  193.           || (alias[j].Zone != found_zone)))
  194.             {
  195.             /* Don't use our point address except to the boss! */
  196.             continue;
  197.             }
  198.  
  199.         if ((alias[j].Domain == curr_domain)
  200.         ||  ((curr_domain == NULL) && (alias[j].Domain == my_addr.Domain)) 
  201.         ||  ((alias[j].Domain == NULL) && (curr_domain == my_addr.Domain)))
  202.             {
  203.             if (k == 0)
  204.                 {
  205.                 assumed = j;
  206.                 ++k;
  207.                 }
  208.  
  209.             if (alias[j].Zone == found_zone)
  210.                 {
  211.                 if (k == 1)
  212.                     {
  213.                     assumed = j;
  214.                     ++k;
  215.                     }
  216.  
  217.                 if (alias[j].Net == found_net)         
  218.                     {
  219.                     assumed = j;
  220.                     break;
  221.                     }
  222.                 }
  223.             }
  224.         }
  225.  
  226.     if (!i && (have_boss_data != 2))
  227.         {
  228.         if (prtflag)
  229.             status_line (MSG_TXT(M_NO_ADDRESS), Full_Addr_Str (bink_addr));
  230.  
  231.         if (curmudgeon && CARRIER && (bink_addr->Net != 0xffff) && (bink_addr->Node != 0xffff) && (bink_addr->Node != 9999)
  232.                                           && ((bink_addr->Zone != alias[0].Zone) || (bink_addr->Net != alias[0].Net)))
  233.             {
  234.             status_line (MSG_TXT(M_NUISANCE_CALLER));
  235.             LOWER_DTR ();                             /* Hang up right now      */
  236.             timer (2);                              /* Wait two secs          */
  237.             RAISE_DTR ();                              /* OK, turn modem back on */
  238.             }
  239.  
  240.         }
  241.  
  242.     if (bink_addr->Zone == (unsigned int) -1)
  243.         return i;
  244.  
  245.     /* If we found the entry, then we promote the file request
  246.      * to the "KNOWN" class. If the password field is non-zero,
  247.      * then promote to "PROT". It's OK to do that since the higher
  248.      * level code will hang up before f.req's if the password does
  249.      * not match.
  250.      *
  251.      */
  252.  
  253.     if (i)
  254.         {
  255.         if (newnodedes.Password[0])
  256.             {
  257.             CURRENT = PROT;         /* Structure assignment */
  258.             }
  259.         else
  260.             {
  261.             CURRENT = KNOWN;
  262.             }
  263.         }
  264.  
  265.     if (!need_boss_data)
  266.         return (i);
  267.  
  268. /*
  269.  *    We can get here one of two ways:
  270.  *
  271.  *    1) No nodelist data was found and this is the BOSS.
  272.  *
  273.  *    2) Nodelist lookup occurred, but this is the BOSS.
  274.  *
  275.  *    For case (1), have_boss_data MUST be 2 (meaning we have
  276.  *    both a phone number and a password entry). If that is the
  277.  *    case, fill in newnodedes with mostly zeroes, plugging in
  278.  *    the BOSS net, node, phone number and password.
  279.  *
  280.  *    For case (2), just see if there is any substitution for
  281.  *    BOSSphone and/or BOSSpwd, then exit.
  282.  *
  283.  */
  284.  
  285.     if (BOSSphone && strlen (BOSSphone) > 2)
  286.         {
  287.         (void) strncpy (newnodedes.PhoneNumber, BOSSphone, 40);
  288.         newnodedes.PhoneNumber[39] = '\0';
  289.         }
  290.  
  291.     if (BOSSpwd && strlen (BOSSpwd) > 2)
  292.         {
  293.         (void) memset (newnodedes.Password, 0, sizeof (newnodedes.Password));
  294.         (void) strncpy (newnodedes.Password, BOSSpwd, 8);
  295.         }
  296.  
  297.     if (i)
  298.         return (1);
  299.  
  300.     /* No BOSS in the nodelist */
  301.     if (have_boss_data != 2)
  302.         {
  303.         status_line (MSG_TXT(M_NO_BOSS));
  304.         return (0);
  305.         }
  306.  
  307.     newnodedes.NodeNumber = bink_addr->Node;                /* Node Number */
  308.     newnodedes.NetNumber = bink_addr->Net;                  /* Net Number  */
  309.     newnodedes.Cost = newnodedes.RealCost = 0;              /* Assume boss is free  */
  310.     (void) strcpy (newnodedes.SystemName, PRDCT_PRTY "'s Boss");/* System Name defaults */
  311.     (void) strcpy (newnodedes.MiscInfo, "Somewhere out There"); /* As does City     */
  312.     newnodedes.HubNode = 0;                                 /* Don't know who's HUB */
  313.     newnodedes.BaudRate = (char) (max_baud.rate_value / 300);
  314.                                                             /* Assume boss speed = ours */
  315.     newnodedes.ModemType = 0;                               /* Or modem type        */
  316.     newnodedes.NodeFlags = B_CM;                            /* Assume boss is CM    */
  317.     newnodedes.NodeFiller = 0;                              /* Zero out filler      */
  318.     return (1);
  319. }
  320.  
  321. #ifdef QUICK_LIST
  322.  
  323. int QuickLookup (ADDRP Quick_addr, int have_boss_data)
  324. {
  325.     register struct QuickNodeIdxRecord far *nodeidx;/* index file             */
  326.     struct QuickNodeListRecord nodedes;             /* desc. of node          */
  327.  
  328.     int foundnet = 0;                               /* 'found the net' flag   */
  329.     int found = 0;                                  /* 'found the node' flag  */
  330.     int idxrec = 0;                                 /* record in QNL_IDX.BBS  */
  331.     long nodeoff = 0L;                              /* offset into QNL_DAT.BBS*/
  332.     char temp[80];                                  /* we build filenames here*/
  333.  
  334.     HFILE stream;
  335.     USHORT i;
  336.     USHORT got;
  337.  
  338.     FILE *stream1;
  339.     struct stat f;
  340.  
  341.     newnodedes.NetNumber = newnodedes.NodeNumber = 0;
  342.  
  343.     if (node_index == NULL)
  344.         {
  345.         index_filesize = (off_t) 0L;                /* Cover error condition  */
  346.         index_filename[0] = '\0';                   /* "null-terminated string*/
  347.         (void) strcpy (index_filename, net_info);   /* take nodelist path     */
  348.         (void) strcat (index_filename, "QNL_IDX.BBS"); /* add in the file name*/
  349.         if ((stream = share_open (index_filename, O_RDONLY|O_BINARY, DENY_WRITE)) == -1)
  350.             {
  351.             if (have_boss_data != 2)
  352.                 status_line (MSG_TXT(M_UNABLE_TO_OPEN), index_filename);
  353.             return (0);                             /* no file, no work to do */
  354.             }
  355.         (void) fstat (stream, &f);                  /* get file statistics    */
  356.         i = (unsigned int) f.st_size;               /* size of index file,    */
  357.         idx_size = i / sizeof (*nodeidx);           /* number of index entries*/
  358.         node_index = get_size (i);
  359.         if (node_index == NULL)
  360.             {
  361.             status_line (MSG_TXT(M_NODELIST_MEM));
  362.             (void) close (stream);
  363.             return (0);
  364.             }
  365.  
  366.         if (_dos_read (stream, node_index, i, &got) != 0)
  367.             {
  368.             status_line (MSG_TXT(M_NODELIST_READ_ERR));
  369.             (void) close (stream);
  370.             return (0);
  371.             }
  372.         (void) close (stream);
  373.  
  374.         index_filesize = f.st_size;                 /* Save params for later  */
  375.         index_filetime = f.st_mtime;
  376.         }
  377.  
  378.     nodeidx = (struct QuickNodeIdxRecord far *) node_index;
  379.  
  380.  
  381.     if (no_zones)
  382.         Quick_addr->Zone = 0;
  383.  
  384.     for (i = 1; i <= idx_size; idxrec++, nodeidx++, i++)
  385.         {
  386.         if (((Quick_addr->Zone == nodeidx->QI_Zone) || (Quick_addr->Zone == 0))
  387.              && (Quick_addr->Net == nodeidx->QI_Net))
  388.             {
  389.             foundnet = 1;                           /* say we found the net   */
  390.             if (((Quick_addr->Node == 0) && (nodeidx->QI_Node <= 0))
  391.                  || (nodeidx->QI_Node == Quick_addr->Node)) /* is it the node?*/
  392.                 {
  393.                 found = 1;                          /* say we found it        */
  394.                 break;                              /* get out                */
  395.                 }
  396.             }
  397.         else if (foundnet)                          /* already past the net?  */
  398.             break;                                  /* Yes, we failed...      */
  399.         }
  400.  
  401.     if (!found)
  402.         {
  403.         return (0);
  404.         }
  405.  
  406.  
  407.     nodeoff = (long) idxrec *(long) sizeof (nodedes);   /* actual file offset */
  408.  
  409.     (void) strcpy (temp, net_info);                 /* take nodelist path     */
  410.     (void) strcat (temp, "QNL_DAT.BBS");            /* add in the file name   */
  411.     if ((stream1 = share_fopen (temp, "rb", DENY_WRITE)) == NULL)   /* open it*/
  412.         {
  413.         status_line (MSG_TXT(M_UNABLE_TO_OPEN), temp);
  414.         return (0);
  415.         }
  416.  
  417.     if (fseek (stream1, nodeoff, SEEK_SET))         /* try to point at record */
  418.         {
  419.         status_line (MSG_TXT(M_NODELIST_SEEK_ERR), temp);
  420.         (void) fclose (stream1);
  421.         return (0);
  422.         }
  423.  
  424.     if (!fread (&nodedes, sizeof (nodedes), 1, stream1))
  425.         {
  426.         status_line (MSG_TXT(M_NODELIST_REC_ERR), temp);
  427.         (void) fclose (stream1);
  428.         return (0);
  429.         }
  430.     (void) fclose (stream1);
  431.  
  432.     /*
  433.      * Copy data from nodedes into newnodedes. 
  434.      */
  435.  
  436.     newnodedes.NodeNumber = nodedes.QL_Node;        /* Node Number  */
  437.     newnodedes.NetNumber = nodedes.QL_Net;          /* Net Number    */
  438.     newnodedes.Cost = nodedes.QL_Cost;              /* Cost            */
  439.  
  440.     i = min (nodedes.QL_Name[0], 19);
  441.     (void) strncpy (&newnodedes.SystemName[0], &nodedes.QL_Name[1], i);
  442.     newnodedes.SystemName[i] = '\0';                /* System Name  */
  443.  
  444.     i = min (nodedes.QL_Phone[0], 39);
  445.     (void) strncpy (&newnodedes.PhoneNumber[0], &nodedes.QL_Phone[1], i);
  446.     newnodedes.PhoneNumber[i] = '\0';               /* Phone Number */
  447.  
  448.     i = min (nodedes.QL_City[0], 29);
  449.     (void) strncpy (&newnodedes.MiscInfo[0], &nodedes.QL_City[1], i);
  450.     newnodedes.MiscInfo[i] = '\0';
  451.  
  452.     /* This field is not necessarily null terminated */
  453.     i = min (nodedes.QL_Password[0], 8);
  454.     (void) strncpy (&newnodedes.Password[0], &nodedes.QL_Password[1], i);
  455.     if (i < 8)
  456.         newnodedes.Password[i] = '\0';
  457.  
  458.     /* Adam Hudson now gives us this, so we might as well use it */
  459.     newnodedes.NodeFlags = nodedes.QL_Flags;
  460.  
  461.     /* Since we have the stuff we need! */
  462.     newnodelist = 1;                                /* We have all the info   */
  463.  
  464.     newnodedes.RealCost = nodedes.QL_Cost;          /* Cost                   */
  465.     newnodedes.HubNode = 0;                         /* Don't know who is Hub  */
  466.     newnodedes.BaudRate = (char) (nodedes.QL_BaudRate / 300);   /* Baud       */
  467.     newnodedes.ModemType = 0;                       /* Don't know modem type  */
  468.     newnodedes.NodeFiller = 0;                      /* Filler should be zero  */
  469.     found_zone = nodeidx -> QI_Zone;                /* Retain the found zone  */
  470.     found_net = nodeidx -> QI_Net;                  /* And the found net      */
  471.     return (1);
  472. }
  473.  
  474. #endif /* QUICK_LIST */
  475.  
  476. int opusfind (ADDRP opus_addr, int have_boss_data)
  477. {
  478.     register struct _ndi far *nodeidx;              /* index file             */
  479.     int found = 0;                                  /* 'found the node' flag  */
  480.     int found_boss = 0;                             /* 'found the boss' flag  */
  481.     int nodeoff = 0;                                /* offset in nodelist.sys */
  482.     char temp[80];                                  /* we build filenames here*/
  483.  
  484.     HFILE stream;
  485.     USHORT i;
  486.     USHORT got;
  487.  
  488.     struct stat f;
  489.     unsigned int current_zone = 0;
  490.  
  491.     newnodedes.NetNumber = newnodedes.NodeNumber = 0;
  492.  
  493.     if (nodelist_base == NULL)
  494.         nodelist_base = nodelist_name;
  495.  
  496.     if  ((node_index == NULLGLOBALPTR)
  497.     ||   ((curr_domain != opus_addr->Domain) && ((opus_addr->Domain != NULL) || (curr_domain != my_addr.Domain))))
  498.         {
  499.         if (node_index != NULL)
  500.             {
  501.             _ffree (node_index);
  502.             }
  503.  
  504.         get_nodelist_name (opus_addr);
  505.         index_filesize = (off_t) 0L;                /* Cover the error case   */
  506.         index_filename[0] = '\0';                   /* "null-terminated string*/
  507.         (void) strcpy (index_filename, net_info);   /* take nodelist path     */
  508.         (void) strcat (index_filename, nodelist_base); /* add in the file name*/
  509.         (void) strcat (index_filename, ".IDX");     /* add in the file ext    */
  510.         if ((stream = share_open(index_filename, O_RDONLY|O_BINARY, DENY_WRITE)) == -1)
  511.             {
  512.             i = 0;                                  /* Need this later        */
  513.             if (have_boss_data != 2)
  514.                 status_line (MSG_TXT(M_UNABLE_TO_OPEN), index_filename);
  515.             return (0);                             /* no file, no work to do */
  516.             }
  517.         (void) fstat (stream, &f);                  /* get file statistics    */
  518.         i = (unsigned int) f.st_size;               /* size of index file,    */
  519.         idx_size = i / sizeof (struct _ndi);        /* number of index entries*/
  520.  
  521.         node_index = get_size (i);
  522.         if (node_index == NULL)
  523.             {
  524.             status_line (MSG_TXT(M_NODELIST_MEM));
  525.             (void) close (stream);
  526.             return (0);
  527.             }
  528.  
  529.         if (_dos_read (stream, node_index, i, &got) != 0)
  530.             {
  531.             status_line (MSG_TXT(M_NODELIST_READ_ERR));
  532.             (void) close (stream);
  533.             return (0);
  534.             }
  535.         (void) close (stream);
  536.  
  537.         index_filesize = f.st_size;                 /* Save params for later  */
  538.         index_filetime = f.st_mtime;
  539.  
  540.         /*
  541.          * Now take into account that the .DAT file can be bigger than we
  542.          * really expect it to be.  Just take the number of records, and
  543.          * divide into the size of the .DAT file to find the true record size
  544.          */
  545.         if (newnodelist)
  546.             {
  547.             temp[0] = '\0';                         /* "null-terminated string*/
  548.             (void) strcpy (temp, net_info);         /* take nodelist path     */
  549.             (void) strcat (temp, nodelist_base);    /* add in the file name   */
  550.             (void) strcat (temp, ".DAT");           /* add in the file name   */
  551.             if (!stat (temp, &f))
  552.                 {
  553.                 extra_bytes = ((int) (f.st_size / idx_size)) - sizeof (newnodedes);
  554.                 }
  555.             }
  556.  
  557.  
  558.         }
  559.  
  560.  
  561.     nodeidx = (struct _ndi far *) node_index;
  562.  
  563.     if ((!newnodelist) || (alias[0].Zone == 0) || (no_zones))
  564.         {
  565.         opus_addr->Zone = 0;
  566.         }
  567.  
  568.     for (i = 1; i <= idx_size; nodeoff++, nodeidx++, i++)
  569.         {
  570.         if (nodeidx->node == -2)
  571.             current_zone = nodeidx->net;
  572.      
  573.         if (opus_addr->Zone > 0 && current_zone != opus_addr->Zone)
  574.             continue;
  575.  
  576.         if ((unsigned)nodeidx->net == opus_addr->Net)   /* if a match on net, */
  577.             {
  578.             if (((opus_addr->Node == 0) && (nodeidx->node <= 0))
  579.             || ((unsigned)nodeidx->node == opus_addr->Node))      
  580.                 {
  581.                 if (opus_addr->Point == 0)
  582.                    {
  583.                    found = 1;                           /* Say we found Node  */
  584.                    break;
  585.                    }
  586.                 found_boss = 1;                         /* say we found Boss  */
  587.                 continue;
  588.                 }
  589.             }
  590.  
  591.         if (nodeidx->net != -1)
  592.            {
  593.            found_boss = 0;
  594.            continue;
  595.            }
  596.  
  597.         if ((found_boss == 1) 
  598.         && ((unsigned)nodeidx->node == opus_addr->Point))
  599.            {
  600.            found = 1;
  601.            break;
  602.            }
  603.  
  604.         }
  605.  
  606.     if (!found)
  607.         return (0);
  608.  
  609.     found_zone = current_zone;                      /* Retain the found zone  */
  610.     found_net  = nodeidx->net;                      /* Keep track of found net*/
  611.  
  612.     if (newnodelist)
  613.         i = (get_new_info (nodeoff));
  614. #ifdef V5_LIST
  615.     else i = (get_old_info (nodeoff));
  616. #endif
  617.  
  618.     return (i);
  619. }
  620.  
  621. #ifdef V5_LIST
  622.  
  623. int get_old_info (unsigned recno)
  624. {
  625.     struct _node nodedes;                           /* desc. of node          */
  626.     long nodeoff;                                   /* Offset in NODELIST.SYS */
  627.     char temp[80];                                  /* we build filenames here*/
  628.     char *c, *ch;
  629.     int i;
  630.     FILE *stream;
  631.  
  632.     nodeoff = (long) recno *(long) sizeof (nodedes); /* actual file offset    */
  633.  
  634.     (void) strcpy (temp, net_info);                  /* take nodelist path    */
  635.     (void) strcat (temp, nodelist_base);             /* add in the file name  */
  636.     (void) strcat (temp, ".SYS");                    /* add in the file name  */
  637.     if ((stream = share_fopen (temp, "rb", DENY_WRITE)) == NULL)/* open it    */
  638.         {
  639.         status_line (MSG_TXT(M_UNABLE_TO_OPEN), temp);
  640.         return (0);
  641.         }
  642.  
  643.     if (fseek (stream, nodeoff, SEEK_SET))           /* try to point at record*/
  644.         {
  645.         status_line (MSG_TXT(M_NODELIST_SEEK_ERR), temp);
  646.         (void) fclose (stream);
  647.         return (0);
  648.         }
  649.  
  650.     if (!fread (&nodedes, sizeof (nodedes), 1, stream))
  651.         {
  652.         status_line (MSG_TXT(M_NODELIST_REC_ERR), temp);
  653.         (void) fclose (stream);
  654.         return (0);
  655.         }
  656.     (void) fclose (stream);
  657.  
  658.     /*
  659.      * Copy data from nodedes into newnodedes. 
  660.      */
  661.  
  662.     newnodedes.NodeNumber = (word) nodedes.number;      /* Node Number  */
  663.     newnodedes.NetNumber = (word) nodedes.net;          /* Net Number    */
  664.     newnodedes.Cost = (word) nodedes.cost;              /* Cost            */
  665.  
  666.     (void) strncpy (&newnodedes.SystemName[0], &nodedes.name[0], 20);
  667.     newnodedes.SystemName[19] = '\0';                   /* System Name  */
  668.  
  669.     (void) strncpy (&newnodedes.PhoneNumber[0], &nodedes.phone[0], 40);
  670.     newnodedes.PhoneNumber[39] = '\0';                  /* Phone Number */
  671.  
  672.     (void) strncpy (&newnodedes.MiscInfo[0], &nodedes.city[0], 30);
  673.     newnodedes.MiscInfo[29] = '\0';
  674.  
  675.     ch = NULL;                                          /* password           */
  676.     c = nodedes.city;                                   /* start of city      */
  677.     i = 37;                                             /* No password if =0  */
  678.     while (i--)                                         /* Enforce that limit */
  679.         {
  680.         if (*c++ != '\0')                               /* If not end of city,*/
  681.             continue;                                   /* go on to next char */
  682.         if (*c++ != '!')                                /* End city, got '!' ?*/
  683.             break;                                      /* No, failure        */
  684.         ch = c;                                         /* Got it, point to it*/
  685.         break;                                          /* Exit with success  */
  686.         }
  687.     if (ch != NULL)
  688.         {
  689.         (void) strncpy (&newnodedes.Password[0], ch, 8);/* Copy the password  */
  690.         }
  691.     else newnodedes.Password[0] = '\0';                 /* Else none          */
  692.  
  693.     newnodedes.RealCost = nodedes.cost;                 /* Cost               */
  694.     newnodedes.HubNode = 0;                             /* Don't know Hub     */
  695.     newnodedes.BaudRate = (char) (nodedes.rate / 300);  /* Baud Rate          */
  696.     newnodedes.ModemType = 0;                           /* Don't know modem   */
  697.     newnodedes.NodeFlags = 0;                           /* Don't know flags   */
  698.     newnodedes.NodeFiller = 0;                          /* Filler must be zero*/
  699.     return (1);
  700. }
  701.  
  702. #endif /* V5_LIST */
  703.  
  704. int get_new_info (unsigned recno)
  705. {
  706.     long nodeoff;                                   /* Offset in NODELIST.DAT */
  707.     char temp[80];                                  /* we build filenames here*/
  708.     FILE *stream;
  709.  
  710.     /* actual file offset */
  711.     nodeoff = (long) recno * ((long) (sizeof (newnodedes) + extra_bytes));
  712.  
  713.     (void) strcpy (temp, net_info);                     /* take nodelist path */
  714.     (void) strcat (temp, nodelist_base);                /* add in the filename*/
  715.     (void) strcat (temp, ".DAT");                       /* then the extension */
  716.     if ((stream = share_fopen (temp, "rb", DENY_WRITE)) == NULL)    /* open it*/
  717.         {
  718.         status_line (MSG_TXT(M_UNABLE_TO_OPEN), temp);
  719.         return (0);
  720.         }
  721.  
  722.     if (fseek (stream, nodeoff, SEEK_SET))              /* point at record    */
  723.         {
  724.         status_line (MSG_TXT(M_NODELIST_SEEK_ERR), temp);
  725.         (void) fclose (stream);
  726.         return (0);
  727.         }
  728.  
  729.     if (!fread (&newnodedes, sizeof (newnodedes), 1, stream))
  730.         {
  731.         status_line (MSG_TXT(M_NODELIST_REC_ERR), temp);
  732.         (void) fclose (stream);
  733.         return (0);
  734.         }
  735.     (void) fclose (stream);
  736.     return (1);
  737. }
  738.  
  739. #ifdef OLDTBBSLIST
  740. int get_TBBS_info (unsigned recno, ADDRP TBBS_addr)
  741. {
  742.     struct nodels nodedes;                          /* desc. of node          */
  743.     struct extrastuff ext;                          /* Extra stuff for Binkley*/
  744.     long nodeoff;                                   /* Offset in NODELIST.DOG */
  745.     char temp[80];                                  /* we build filenames here*/
  746.     FILE *stream;
  747.  
  748.     --recno;                                            /* TBBS starts at 1st *
  749.                                                          * record - no filler */
  750.  
  751.     nodeoff = (long) recno *(long) sizeof (nodedes);    /* actual file offset */
  752.  
  753.     (void) strcpy (temp, net_info);                     /* take nodelist path */
  754.     (void) strcat (temp, "NODELIST.DOG");               /* add in the filename*/
  755.     if ((stream = share_fopen (temp, "rb", DENY_WRITE)) == NULL)    /* open it*/
  756.         {
  757.         status_line (MSG_TXT(M_UNABLE_TO_OPEN), temp);
  758.         return (0);
  759.         }
  760.  
  761.     if (fseek (stream, nodeoff, SEEK_SET))              /* point at record    */
  762.         {
  763.         status_line (MSG_TXT(M_NODELIST_SEEK_ERR), temp);
  764.         (void) fclose (stream);
  765.         return (0);
  766.         }
  767.  
  768.     if (!fread (&nodedes, sizeof (nodedes), 1, stream))
  769.         {
  770.         status_line (MSG_TXT(M_NODELIST_REC_ERR), temp);
  771.         (void) fclose (stream);
  772.         return (0);
  773.         }
  774.     (void) fclose (stream);
  775.  
  776.     /*
  777.      * Copy data from nodedes into newnodedes. 
  778.      */
  779.  
  780.     newnodedes.NodeNumber = TBBS_addr->Node;            /* Node Number        */
  781.     newnodedes.NetNumber = TBBS_addr->Net;              /* Net Number         */
  782.     newnodedes.Cost = nodedes.nodecost;                 /* Cost               */
  783.  
  784.     (void) strncpy (&newnodedes.SystemName[0], &nodedes.nodename[0], 14);
  785.     newnodedes.SystemName[19] = '\0';                   /* System Name        */
  786.  
  787.     (void) strncpy (&newnodedes.PhoneNumber[0], &nodedes.nodephone[0], 40);
  788.     newnodedes.PhoneNumber[39] = '\0';                  /* Phone Number       */
  789.  
  790.     (void) strncpy (&newnodedes.MiscInfo[0], &nodedes.nodecity[0], 30);
  791.     newnodedes.MiscInfo[29] = '\0';
  792.  
  793.     newnodedes.Password[0] = '\0';                      /* Else set zero length*/
  794.  
  795.     newnodedes.RealCost = nodedes.nodecost;             /* Cost               */
  796.     newnodedes.HubNode = nodedes.nodehub;               /* Hub                */
  797.     newnodedes.BaudRate = (char) (nodedes.nodebaud / 300);  /* Baud Rate      */
  798.     newnodedes.ModemType = 0;                           /* Don't know modem   */
  799.     newnodedes.NodeFlags = 0;                           /* Don't know flags   */
  800.     newnodedes.NodeFiller = 0;                          /* Filler must be zero*/
  801.  
  802.     /* Now get information from secondary file */
  803.     ++recno;
  804.     nodeoff = (long) recno *(long) sizeof (ext);        /* actual file offset */
  805.  
  806.     (void) strcpy (temp, net_info);                     /* take nodelist path */
  807.     (void) strcat (temp, "NODELIST.EXT");               /* add in the filename*/
  808.     newnodelist = 0;
  809.     if ((stream = share_fopen (temp, "rb", DENY_WRITE)) == NULL)    /* open it*/
  810.         {
  811.         return (1);
  812.         }
  813.  
  814.     if (fseek (stream, nodeoff, SEEK_SET))          /* try to point at record */
  815.         {
  816.         (void) fclose (stream);
  817.         return (1);
  818.         }
  819.  
  820.     if (!fread (&ext, sizeof (ext), 1, stream))
  821.         {
  822.         (void) fclose (stream);
  823.         return (1);
  824.         }
  825.     (void) fclose (stream);
  826.  
  827.     /*
  828.      * Copy data from ext into newnodedes. 
  829.      */
  830.  
  831.     (void) strncpy (newnodedes.Password, ext.password, 8);  /* Password       */
  832.  
  833.     newnodedes.NodeFlags = ext.flags1;                  /* Nodelist flags     */
  834.     newnodedes.ModemType = ext.modem;                   /* Modem type         */
  835.     newnodelist = 1;                                    /* We've all the info */
  836.     return (1);
  837. }
  838.  
  839. int TBBSLookup (ADDRP TBBS_addr, int have_boss_data)
  840. {
  841.     register struct _ndi far *nodeidx;              /* index file             */
  842.     int found = 0;                                  /* 'found the node' flag  */
  843.     int nodeoff = 0;                                /* offset in nodelist.sys */
  844.     char temp[80];                                  /* we build filenames here*/
  845.  
  846.     HFILE stream;
  847.     USHORT i;
  848.     USHORT got;
  849.  
  850.     struct stat f;
  851.     unsigned int current_zone = 0;
  852.  
  853.     newnodedes.NetNumber = newnodedes.NodeNumber = 0;
  854.  
  855.     if (node_index == NULL)
  856.         {
  857.         temp[0] = '\0';                             /* "null-terminated string*/
  858.         (void) strcpy (temp, net_info);             /* take nodelist path     */
  859.         (void) strcat (temp, "NODELIST.IDX");       /* add in the file name   */
  860.         if ((stream = share_open(temp, O_RDONLY|O_BINARY, DENY_WRITE)) == -1)
  861.             {
  862.             i = 0;                                  /* Need this later        */
  863.             if (have_boss_data != 2)
  864.                 status_line (MSG_TXT(M_UNABLE_TO_OPEN), temp);
  865.             return (0);                             /* no file, no work to do */
  866.             }
  867.         (void) fstat (stream, &f);                  /* get file statistics    */
  868.         i = (unsigned int) f.st_size;               /* size of index file,    */
  869.         idx_size = i / sizeof (struct _ndi);        /* number of index entries*/
  870.         node_index = get_size (i);
  871.         if (node_index == NULL)
  872.             {
  873.             status_line (MSG_TXT(M_NODELIST_MEM));
  874.             (void) close (stream);
  875.             return (0);
  876.             }
  877.  
  878.         if (_dos_read (stream, node_index, i, &got) != 0)
  879.             {
  880.             status_line (MSG_TXT(M_NODELIST_READ_ERR));
  881.             (void) close (stream);
  882.             return (0);
  883.             }
  884.         (void) close (stream);
  885.         }
  886.     nodeidx = (struct _ndi far *) node_index;
  887.  
  888.     if (TBBS_addr->Zone == (unsigned int) -1)
  889.         {
  890.         return (opus_next_zone ());
  891.         }
  892.  
  893.     for (i = 1; i <= idx_size; nodeoff++, nodeidx++, i++)
  894.         {
  895.         if (nodeidx->node == -2)
  896.         current_zone = nodeidx->net;
  897.      
  898.         if (TBBS_addr->Zone > 0 && current_zone != TBBS_addr->Zone)
  899.                 continue;
  900.  
  901.         if ((unsigned)nodeidx->net == TBBS_addr->Net)   /* if a match on net, */
  902.             {
  903.             if (((TBBS_addr->Node == 0) && (nodeidx->node <= 0))
  904.                  || ((unsigned)nodeidx->node == TBBS_addr->Node))
  905.                                                         /* is this the node?  */
  906.                 {
  907.                 found = 1;                              /* say we found it    */
  908.                 break;                                  /* get out            */
  909.                 }
  910.             }
  911.         }
  912.  
  913.     if (!found)
  914.         return (0);
  915.  
  916.     found_zone = current_zone;                      /* Retain the found zone  */
  917.     found_net  = nodeidx->net;                      /* Keep track of found net*/
  918.  
  919.     i = get_TBBS_info (nodeoff, TBBS_addr);
  920.  
  921.     return (i);
  922. }
  923.  
  924. #endif /* defined OLDTBBSLIST */
  925.