home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / gopherd / gopherdconf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  5.9 KB  |  275 lines

  1. /********************************************************************
  2.  * $Author: lindner $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1992/12/10 23:13:27 $
  5.  * $Source: /home/mudhoney/GopherSrc/release1.11/gopherd/RCS/gopherdconf.c,v $
  6.  * $Status: $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: gopherdconf.c
  14.  * Routines to parse the gopherd.conf file.
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: gopherdconf.c,v $
  18.  * Revision 1.1  1992/12/10  23:13:27  lindner
  19.  * gopher 1.1 release
  20.  *
  21.  *
  22.  *********************************************************************/
  23.  
  24.  
  25. #include "gopherdconf.h"
  26. #include "Malloc.h"
  27. #include "String.h"
  28. #include <stdio.h>
  29.  
  30. extern boolean DEBUG;
  31.  
  32. /*********************************************/
  33.  
  34. GDCobj *
  35. GDCnew()
  36. {
  37.      GDCobj *gdc;
  38.  
  39.      gdc = (GDCobj *) malloc(sizeof(GDCobj));
  40.  
  41.      gdc->Extensions = ExtArrayNew();
  42.  
  43.      gdc->Sites      = SiteArrayNew();
  44.      gdc->Securityon   = FALSE;
  45.  
  46.      gdc->RunFromInetd = FALSE;
  47.      gdc->Caching      = TRUE;
  48.  
  49.      gdc->Logfile      = STRnew();
  50.      gdc->Data_Dir     = STRnew();
  51.      gdc->Hostname     = STRnew();
  52.      gdc->Port         = 0;
  53.      gdc->chroot       = TRUE;
  54.      gdc->Defaccess    = ACC_FULL;
  55.      gdc->BummerMsg    = STRnew();
  56.      
  57.      gdc->Admin        = STRnew();
  58.      gdc->AdminEmail   = STRnew();
  59.  
  60.      gdc->Site         = STRnew();
  61.      gdc->Org          = STRnew();
  62.      gdc->Geog         = STRnew();
  63.      gdc->Loc          = STRnew();
  64.  
  65.      gdc->TZ           = 0;
  66.  
  67.      STRset(gdc->Logfile, "");
  68.      STRset(gdc->BummerMsg, "");
  69.      STRset(gdc->Hostname, "");
  70.  
  71.      return(gdc);
  72. }
  73.  
  74. void
  75. GDCdestroy(gdc)
  76.   GDCobj *gdc;
  77. {
  78.      ExtArrDestroy(gdc->Extensions);
  79.      SiteArrDestroy(gdc->Sites);
  80.  
  81. }
  82.  
  83.  
  84. boolean
  85. GDCtokens(gdc, token, rest)
  86.   GDCobj *gdc;
  87.   char *token;
  88.   char *rest;
  89. {
  90.      boolean success = TRUE;
  91.  
  92.      if (DEBUG)
  93.       printf("Parsed token '%s', rest of line '%s'\n", token, rest);
  94.      
  95.      if (strcasecmp(token, "ACCESS") == 0) {
  96.       int moo;
  97.       success = SiteProcessLine(gdc->Sites, rest, gdc->Defaccess);
  98.       moo = SiteAccess(gdc->Sites, "default");
  99.       if (moo != ACC_UNKNOWN)
  100.            gdc->Defaccess = moo;
  101.  
  102.       gdc->Securityon = TRUE;
  103.      }
  104.  
  105.      else if (strcasecmp(token, "ADMIN")==0)
  106.       GDCsetAdmin(gdc, rest);
  107.      else if (strcasecmp(token, "ADMINEMAIL")==0)
  108.       GDCsetAdminEmail(gdc, rest);
  109.      else if (strcasecmp(token, "HOSTALIAS")==0)
  110.       GDCsetHostname(gdc, rest);
  111.      else if (strcasecmp(token, "SITE")==0)
  112.       GDCsetSite(gdc, rest);
  113.      else if (strcasecmp(token, "ORG")==0)
  114.       GDCsetOrg(gdc, rest);
  115.      else if (strcasecmp(token, "LOC")==0)
  116.       GDCsetLoc(gdc, rest);
  117.      else if (strcasecmp(token, "LOGFILE")==0)
  118.       GDCsetLogfile(gdc, rest);
  119.      else if (strcasecmp(token, "BUMMERMSG")==0)
  120.       GDCsetBummerMsg(gdc, rest);
  121.      else if (strcasecmp(token, "EXT")==0) {
  122.       success = ExtProcessLine(gdc->Extensions, rest);
  123.      }
  124.      else if (strcasecmp(token, "IGNORE")==0) {
  125.       ExtAdd(gdc->Extensions, '3', "","",rest);
  126.      }
  127.      else
  128.       success = FALSE;
  129.      
  130.      return(success);
  131. }
  132.  
  133. void
  134. GDCfromFile(gdc, filename)
  135.   GDCobj *gdc;
  136.   char *filename;
  137. {
  138.      FILE *gdcfile;
  139.      char inputline[256];
  140.      char *cp, *token, *restofline;
  141.      boolean success;
  142.  
  143.  
  144.      if ((gdcfile = fopen(filename, "r")) == (FILE *) NULL) {
  145.       printf("Cannot open file '%s'\n", filename);
  146.       exit(-1);
  147.      }
  148.  
  149.      while (fgets(inputline, sizeof inputline, gdcfile)!= NULL) {
  150.       ZapCRLF(inputline);
  151.       
  152.       if (*inputline == '#' || *inputline == '\0') /** Ignore comments **/
  153.            continue;
  154.  
  155.       cp = strchr(inputline, ':');
  156.       if (cp == NULL) {
  157.            fprintf(stderr, "Bad line '%s'\n", inputline);
  158.            exit(-1);
  159.       }
  160.       *cp = '\0';
  161.       token      = inputline;
  162.       restofline = cp+1;
  163.       while (*restofline == ' ' || *restofline == '\t')
  164.            restofline++;
  165.       
  166.       success = GDCtokens(gdc, token, restofline);
  167.       if (!success) {
  168.            fprintf(stderr, "Bad line '%s'\n", inputline);
  169.            exit(-1);
  170.       }
  171.      }
  172.      
  173.      fclose(gdcfile);
  174. }
  175.  
  176.  
  177. boolean GDCCanSearch(gdc, hostname, ipnum)
  178.   GDCobj *gdc;
  179.   char *hostname, *ipnum;
  180. {
  181.      boolean test;
  182.  
  183.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  184.  
  185.      if (gdc->Securityon == FALSE)
  186.       return(TRUE);
  187.  
  188.      if ((test = SiteArrCanSearch(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  189.       return(test);
  190.      
  191.      if ((gdc->Defaccess & ACC_SEARCH) == ACC_SEARCH)
  192.       return(TRUE);
  193.      else
  194.       return(FALSE);
  195.  
  196. }
  197.  
  198. boolean GDCCanRead(gdc, hostname, ipnum)
  199.   GDCobj *gdc;
  200.   char *hostname, *ipnum;
  201. {
  202.      boolean test;
  203.  
  204.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  205.  
  206.      if (gdc->Securityon == FALSE)
  207.       return(TRUE);
  208.  
  209.      if ((test = SiteArrCanRead(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  210.       return(test);
  211.      
  212.      if ((gdc->Defaccess & ACC_READ) == ACC_READ)
  213.       return(TRUE);
  214.      else
  215.       return(FALSE);
  216.  
  217. }
  218.  
  219.  
  220. boolean GDCCanBrowse(gdc, hostname, ipnum)
  221.   GDCobj *gdc;
  222.   char *hostname, *ipnum;
  223. {
  224.      boolean test;
  225.  
  226.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  227.  
  228.      if (gdc->Securityon == FALSE)
  229.       return(TRUE);
  230.  
  231.      if ((test = SiteArrCanBrowse(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  232.       return(test);
  233.      
  234.      if ((gdc->Defaccess & ACC_BROWSE) == ACC_BROWSE)
  235.       return(TRUE);
  236.      else
  237.       return(FALSE);
  238.  
  239. }
  240.  
  241.  
  242. /** Is this file ignored? **/
  243. boolean
  244. GDCignore(gdc, filenm)
  245.   GDCobj *gdc;
  246.   char *filenm;
  247. {
  248.      char *gplustype, *prefix, objtype;
  249.  
  250.      ExtGet(gdc->Extensions, filenm, &objtype, &gplustype, &prefix);
  251.  
  252.      if (objtype == '3')
  253.       return(TRUE);
  254.      else
  255.       return(FALSE);
  256. }
  257.  
  258.  
  259. boolean 
  260. GDCExtension(gdc, ext, Gtype, Prefix)
  261.   GDCobj *gdc;
  262.   char *ext;
  263.   char *Gtype;
  264.   char **Prefix;
  265. {
  266.      char *gplustype;
  267.  
  268.      ExtGet(gdc->Extensions, ext, Gtype, &gplustype, Prefix);
  269.  
  270.      if (*Gtype != '\0')
  271.       return(TRUE);
  272.      else
  273.       return(FALSE);
  274. }
  275.