home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / table / tb_getchan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.3 KB  |  176 lines

  1. /* tb_getchan.c - maps a Next Hop hostname into its outgoing channel pairs */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/table/RCS/tb_getchan.c,v 6.0 1991/12/18 20:24:28 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/table/RCS/tb_getchan.c,v 6.0 1991/12/18 20:24:28 jpo Rel $
  9.  *
  10.  * $Log: tb_getchan.c,v $
  11.  * Revision 6.0  1991/12/18  20:24:28  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "list_rchan.h"
  20.  
  21.  
  22.  
  23. static Table            *Channel = NULLTBL;
  24. static int        CH_str2rchan ();
  25. static int         CH_doparse ();
  26.  
  27. /* ---------------------  Begin  Routines --------------------------------- */
  28.  
  29.  
  30.  
  31.  
  32. /* --- *** Start Description *** ---
  33.  
  34. tb_getchan (key, rp)
  35.     char            *key;
  36.     LIST_RCHAN      **rp;
  37.  
  38. Parameters required:
  39.     - The Next Hop hostname (key)
  40.     - A pointer to the list of channel pairs used to get to the
  41.       Next Hop hostname (rp)
  42.  
  43. Example:
  44.     key     =  torch.co.uk
  45.     rp      =  li_mta = ukc.ac.uk     li_chan = JANET
  46.            li_mta = stl.stc.co.uk li_chan = PSS
  47.  
  48. Routine:
  49.     - Reads the channel table
  50.     - Updates rp
  51.     - Returns OK or NOTOK.
  52.  
  53.  
  54. Note:
  55.     - This routine always fills in ad_outchan with hostnames in US order.
  56.  
  57.  
  58. --- *** End Description *** --- */
  59.  
  60.  
  61.  
  62.  
  63. /* ------------------------------------------------------------------------ */
  64.  
  65.  
  66. extern    char    *channel_tbl;
  67.  
  68. int tb_getchan (key, rp)
  69. char                    *key;
  70. LIST_RCHAN              **rp;
  71. {
  72.     char            tbuf[BUFSIZ];
  73.  
  74.     PP_DBG (("Lib/table/tb_getchan ('%s')", key));
  75.  
  76.     if (Channel == NULLTBL)
  77.         if ((Channel = tb_nm2struct (channel_tbl)) == NULLTBL) {
  78.             PP_LOG (LLOG_EXCEPTIONS,
  79.                 ("Lib/tb_getchan channel table not found"));
  80.             return NOTOK ;
  81.         }
  82.  
  83.     if (tb_k2val (Channel, key, tbuf, TRUE) == NOTOK) {
  84.         PP_LOG (LLOG_EXCEPTIONS,
  85.             ("Lib/tb_getchan key '%s' not found.POSSIBLE INTERNAL INCONSISTENCY BETWEEN TABLES", key));
  86.         return NOTOK ;
  87.     }
  88.  
  89.     if (*rp != NULLIST_RCHAN) {
  90.         PP_LOG (LLOG_EXCEPTIONS,
  91.             ("Lib/tb_getchan list is already set!"));
  92.         return NOTOK ;
  93.     }
  94.  
  95.     /* -- free all memory -- */
  96.     if (CH_str2rchan (rp, tbuf) == NOTOK) {
  97.         PP_DBG (("Lib/table/tb_getchan free list!"));
  98.         list_rchan_free (*rp);
  99.         *rp = NULLIST_RCHAN;
  100.         return NOTOK ;
  101.     }
  102.  
  103.     return OK;
  104. }
  105.  
  106.  
  107.  
  108.  
  109. /* ---------------------  Static  Routines  ------------------------------- */
  110.  
  111.  
  112.  
  113. static int CH_str2rchan (rp, str)
  114. LIST_RCHAN              **rp;
  115. char                    *str;
  116. {
  117.     LIST_RCHAN      *list;
  118.     char            *host = NULLCP,
  119.             *chan = NULLCP,
  120.             *next = NULLCP;
  121.     int             retval;
  122.  
  123.  
  124.     PP_DBG (("Lib/table/CH_str2rchan ('%s')", str));
  125.  
  126.     *rp = NULLIST_RCHAN;
  127.  
  128.     while ((retval = CH_doparse (str, &host, &chan, &next)) == OK) {
  129.         if ((list = list_rchan_new(host, chan)) != NULLIST_RCHAN)
  130.             list_rchan_add (rp, list);
  131.  
  132.         if (next) 
  133.             str = next; 
  134.         else 
  135.             break;
  136.     }
  137.  
  138.     if (retval == NOTOK || *rp == NULLIST_RCHAN)
  139.         return NOTOK;
  140.     return OK;
  141. }
  142.  
  143.  
  144.  
  145. static int CH_doparse (str, host, chan, next)
  146. char            *str;
  147. char            **host;
  148. char            **chan;
  149. char            **next;
  150. {
  151.     char *cp;
  152.  
  153.     PP_DBG (("Lib/table/CH_doparse ('%s')", str));
  154.  
  155.     if ((cp = index (str, ',')) == NULLCP) 
  156.         *next = NULLCP;  
  157.     else 
  158.         *next = ++cp; 
  159.  
  160.     *host = str;
  161.     if ((cp = index (str, '(')) == NULLCP)
  162.         return NOTOK;
  163.     if (*host == cp)
  164.         *host = NULLCP;
  165.     else
  166.         *cp = '\0';
  167.     cp++;
  168.     *chan = cp;
  169.  
  170.     if ((cp = index (*chan, ')')) == NULLCP)
  171.         return NOTOK;
  172.     *cp  = '\0';
  173.  
  174.     return OK;
  175. }
  176.