      SUBROUTINE PLIP.READ.CONFIG(MAT PLIP$VARS)
*PIC-LAN
*
*ALL
*PC
*N
*
*
*
*
******************************************************************************
******************************************************************************
***                                                                        ***
*** (C) Copyright 1990-2005 Doug Dumitru, All Rights Reserved.             ***
***                                                                        ***
*** This program is licensed under the terms of the GNU General Public     ***
*** License, version 2.0 with attached notices.                            ***
***                                                                        ***
*** The full text can be found in the LICENSE.TXT file in the              ***
*** PLIP.BP database file (the /usr/qmweb/PLIP.BP/PLIP.BP directory).      ***
***                                                                        ***
******************************************************************************
******************************************************************************
*
      INCLUDE SYS.TYPE.INCLUDE
*
      DIM PLIP$VARS(100)
*
      INCLUDE PLIP.VARS
*
      OPEN 'PLIP.CTRL' TO CTRL.FD ELSE CALL PLXX.STOP(201,'PLIP.CTRL')
*
      READU SRC FROM CTRL.FD , 'CONFIG' ELSE CALL PLXX.STOP(202,'CONFIG')
      READ SRC0 FROM CTRL.FD , 'CONFIG-CACHE' ELSE SRC0 = ''
*
      IF SRC = SRC0 THEN
         MATREAD PLIP$VARS FROM CTRL.FD , 'CONFIG-OBJ' ELSE CALL PLXX.STOP(202,'CONFIG-OBJ')
         RELEASE CTRL.FD , 'CONFIG'
         RETURN
      END
*
      MAT PLIP$VARS = ''
*
      W.LIST = ''
      W.LIST<-1> = 'CONN CLEANUP'       : VM : PLIP$$CONN.CLEANUP      : VM : '1N0N' : VM : '00:05:00' : VM : 'MTS'
      W.LIST<-1> = 'LOCAL HOST NAME'    : VM : PLIP$$LOCAL.HOST.NAME   : VM :          VM :         VM : 'MCL'
      W.LIST<-1> = 'CONN'               : VM : PLIP$$CONN              : VM : '1N0N' : VM : 200
      W.LIST<-1> = 'WEB BW'             : VM : PLIP$$WEBBW             : VM : '1N0N' : VM : 2
      W.LIST<-1> = 'WEB BW SEC'         : VM : PLIP$$WEBBWSEC          : VM : '1N0N' : VM : 0
      W.LIST<-1> = 'OTH BW'             : VM : PLIP$$OTHBW             : VM : '1N0N' : VM : 2
      W.LIST<-1> = 'OTH BW SEC'         : VM : PLIP$$OTHBWSEC          : VM : '1N0N' : VM : 0
      W.LIST<-1> = 'PICLAN-IP SN'       : VM : PLIP$$PICLANIPSN        : VM : '1N0N'
      W.LIST<-1> = 'SUPERVISOR POLL'    : VM : PLIP$$SUP.POLL          : VM : '1N0N' : VM : '00:00:10' : VM : 'MTS'
      W.LIST<-1> = 'SUPERVISOR TIMEOUT' : VM : PLIP$$SUP.TIMEOUT       : VM : '1N0N' : VM : '00:01:30' : VM : 'MTS'
      W.LIST<-1> = 'WWW TIMEOUT'        : VM : PLIP$$WWW.TIMEOUT       : VM : '1N0N' : VM : '00:01:30' : VM : 'MTS'
      W.LIST<-1> = 'WWW CACHE TIMEOUT'  : VM : PLIP$$WWW.CACHE.TIMEOUT : VM : '1N0N' : VM : '00:00:10' : VM : 'MTS'
      W.LIST<-1> = 'WWW LOG OPT'        : VM : PLIP$$WWW.LOG.OPT       : VM : ''     : VM : 'FIB'
      W.LIST<-1> = 'HTTP MAX HDR'       : VM : PLIP$$MAX.HTTP.HDR      : VM : '1N0N' : VM : 500000
      W.LIST<-1> = 'RPC NAME'           : VM : PLIP$$RPC.NAME          : VM : '' : VM
      W.LIST<-1> = 'RPC KEY'            : VM : PLIP$$RPC.KEY           : VM : '' : VM
      W.LIST<-1> = 'TZ ZONE'            : VM : PLIP$$TZ.ZONE           : VM : '' : VM : '-0700'
      W.LIST<-1> = 'NOKEEPALIVE'        : VM : PLIP$$NOKEEPALIVE       : VM : '1N'   : VM : 0
      W.LIST<-1> = 'PLZ CLEANUP SUP'    : VM : PLIP$$PLZ.CLEANUP.FLG   : VM : '1N'   : VM : 0
*
      W.LIST<-1> = 'COMM PATH'          : VM : PLIP$$COMM.PATH          : VM : '' : VM   
      W.LIST<-1> = 'COMM ADDR'          : VM : PLIP$$COMM.ADDR          : VM : '' : VM   
      W.LIST<-1> = 'COMM TP'            : VM : PLIP$$COMM.TP            : VM : '' : VM   
      W.LIST<-1> = 'HOST TP'            : VM : PLIP$$HOST.TP            : VM : '' : VM
      W.LIST<-1> = 'RESTART COUNTER'    : VM : PLIP$$RESTART.CTR       : VM : '1N0N' : VM : 0
*
      W.LIST<-1> = 'MAX IO LEN'         : VM : PLIP$$MAX.IO.LEN        : VM : '1N0N'
*
      DEF.GATEWAY = ''
*
      LOOP
         SRC.OLD = SRC
         SRC = PL_REPL(SRC,AM:'  ',AM:' ')
      WHILE SRC <> SRC.OLD DO REPEAT
      LOOP
         SRC.OLD = SRC
         SRC = PL_REPL(SRC,' ':AM,AM)
      WHILE SRC <> SRC.OLD DO REPEAT
      SRC = PL_REPL(SRC,AM:' ',' ')
      LOOP WHILE SRC[LEN(SRC),1] = ' ' DO
         SRC = SRC[1,LEN(SRC)-1]
      REPEAT
*
      I1 = DCOUNT(SRC,AM)
      J1 = DCOUNT(W.LIST,AM)
      FOR I = 1 TO I1
         W = OCONV(TRIM(FIELD(SRC<I>,'=',1)),'MCU')
         V = OCONV(TRIM(FIELD(SRC<I>,'=',2)),'MCU')
*
         FLG = NO
         FOR J = 1 TO J1 UNTIL FLG
            IF W.LIST<J,1> = W THEN
               IF PLIP$VARS(W.LIST<J,2>) <> '' THEN
                  PRINT 'Duplicate value for ' : W
                  STOP
               END
               IF W.LIST<J,5> <> '' THEN
                  VV = ICONV(V,W.LIST<J,5>)
               END ELSE
                  VV = V
               END
               IF W.LIST<J,3> <> '' THEN
                  IF NOT( VV MATCHES W.LIST<J,3> ) THEN
                     PRINT 'Config item ' : W : '=' : VV : ' does not match ' : W.LIST<J,3>
                     STOP
                  END
               END
               PLIP$VARS(W.LIST<J,2>) = VV
               FLG = YES
            END
         NEXT J
*
         BEGIN CASE
            CASE FLG
            CASE W = ''
            CASE W[1,1] = '*'
            CASE W[1,3] = 'REM'
            CASE W = 'ADDR'
               GOSUB 100
               PLIP$MYIPS<1,-1> = V
            CASE W = 'MASK'
               IF PLIP$MASK <> '' THEN
                  PRINT 'Duplicate MASK value in configuration'
                  STOP
               END
               GOSUB 100
               PLIP$MASK = V
            CASE W = 'DEFAULT GATEWAY'
               IF DEF.GATEWAY <> '' THEN
                  PRINT 'Duplicate DEFAULT GATEWAY value in configuration'
                  STOP
               END
               GOSUB 100
               DEF.GATEWAY = V
            CASE W = 'ROUTE'
               VV = V
               V = FIELD(VV,' ',1) ; GOSUB 100
               V = FIELD(VV,' ',2) ; GOSUB 100
               V = FIELD(VV,' ',3) ; GOSUB 100
               PLIP$ROUTES<1,-1> = VV
            CASE W = 'SUPERVISOR'
               IF PLIP$SUP.PORT <> '' THEN
                  PRINT 'Duplication SUPERVISOR value in cofiguration'
                  STOP
               END
               IF V = '*' THEN
                  PLIP$SUP.PORT = V
               END ELSE
                  GOSUB 200
                  PLIP$SUP.PORT = V
               END
            CASE W = 'PROCESS'
               IF V = '*' THEN
                  PLIP$PROC.PORTS<1,-1> = V
               END ELSE
                  GOSUB 200
                  PLIP$PROC.PORTS<1,-1> = V
               END
            CASE W = 'INITSUB'
               PLIP$INIT.SUBS<1,-1> = V
            CASE W[1,5] = 'HTTP '
            CASE W[1,7] = 'DAEMON '
            CASE W[1,4] = 'RPC '
            CASE W[1,4] = 'EXT '
            CASE YES
               PRINT 'Unknown keyword in PLIP.CTRL CONFIG = ' : W
               STOP
         END CASE
      NEXT I
*
      IF PLIP$MYIPS = '' THEN
         PRINT 'No local IP address specified in configuration'
         STOP
      END
*
      FOR J = 1 TO J1
         IF W.LIST<J,4> <> '' THEN
            IF PLIP$VARS(W.LIST<J,2>) = '' THEN
               IF W.LIST<J,5> <> '' THEN
                  PLIP$VARS(W.LIST<J,2>) = ICONV(W.LIST<J,4>,W.LIST<J,5>)
               END ELSE
                  PLIP$VARS(W.LIST<J,2>) = W.LIST<J,4>
               END
            END
         END
      NEXT J
*
      IF DEF.GATEWAY <> '' THEN
         PLIP$ROUTES<1,-1> = '0.0.0.0 0.0.0.0 ' : DEF.GATEWAY
      END
*
      PLIP$TZ = PLIP$TZ.ZONE
      IF PLIP$TZ[1,1] = '+' THEN PLIP$TZ = PLIP$TZ[2,99]
      PLIP$TZ = PLIP$TZ / 100
      PLIP$TZ = PLIP$TZ * 3600
*
      IF NOT(PLIP$MAX.IO.LEN MATCHES '1N0N') THEN PLIP$MAX.IO.LEN = 0
      IF NOT(PLIP$MAX.IO.LEN) THEN
         PLIP$MAX.IO.LEN = 8000
      END
*
      MATWRITE PLIP$VARS ON CTRL.FD , 'CONFIG-OBJ'
      WRITE SRC ON CTRL.FD , 'CONFIG-CACHE'
      RELEASE CTRL.FD , 'CONFIG'
*
      RETURN
*
100   REM Validate V as IP address
*
      IF NOT( V MATCHES '1N0N.1N0N.1N0N.1N0N' ) THEN
         PRINT 'Invalid IP address ' : V
         STOP
      END
*
      IF V # PL_HEXTOIP(PL_IPTOHEX(V)) THEN
         PRINT 'Invalid IP address ' : V
         STOP
      END
*
      RETURN
*
200   REM Validate V as an integer
*
      IF NOT( V MATCHES '1N0N' ) THEN
         PRINT 'Invalid value ' : V
         STOP
      END
*
      RETURN
*
300   REM Validate string as an integer list
*
      CALL PLU.NUM.LIST(V,R,R.ERR)
*
      IF R.ERR <> '' THEN
         PRINT R.ERR
         STOP
      END
*
      RETURN
   END
