home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / gopherd / gopherdconf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-15  |  7.4 KB  |  346 lines

  1. /********************************************************************
  2.  * lindner
  3.  * 3.3
  4.  * 1993/04/15 17:09:22
  5.  * /home/mudhoney/GopherSrc/CVS/gopher+/gopherd/gopherdconf.c,v
  6.  * Exp
  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.  * gopherdconf.c,v
  18.  * Revision 3.3  1993/04/15  17:09:22  lindner
  19.  * none
  20.  *
  21.  * Revision 3.2  1993/03/24  20:25:14  lindner
  22.  * Addition for secureusers file
  23.  *
  24.  * Revision 3.1.1.1  1993/02/11  18:02:51  lindner
  25.  * Gopher+1.2beta release
  26.  *
  27.  * Revision 1.3  1993/02/09  22:30:56  lindner
  28.  * Additions for multi-languages
  29.  *
  30.  * Revision 1.2  1993/01/30  23:57:44  lindner
  31.  * Gopher+ stuff
  32.  *
  33.  * Revision 1.1  1992/12/10  23:13:27  lindner
  34.  * gopher 1.1 release
  35.  *
  36.  *
  37.  *********************************************************************/
  38.  
  39.  
  40. #include "gopherdconf.h"
  41. #include "Malloc.h"
  42. #include "String.h"
  43. #include <stdio.h>
  44. #include "util.h"
  45.  
  46. extern boolean DEBUG;
  47.  
  48. /*********************************************/
  49.  
  50. GDCobj *
  51. GDCnew()
  52. {
  53.      GDCobj *gdc;
  54.  
  55.      gdc = (GDCobj *) malloc(sizeof(GDCobj));
  56.  
  57.      gdc->Extensions = EXAnew();
  58.  
  59.      gdc->Sites      = SiteArrayNew();
  60.      gdc->Securityon   = FALSE;
  61.  
  62.      gdc->RunFromInetd = FALSE;
  63.      gdc->Caching      = TRUE;
  64.  
  65.      gdc->Logfile      = STRnew();
  66.      gdc->Data_Dir     = STRnew();
  67.      gdc->Hostname     = STRnew();
  68.      gdc->Port         = 0;
  69.      gdc->chroot       = TRUE;
  70.      gdc->Defaccess    = ACC_FULL;
  71.      gdc->BummerMsg    = STRnew();
  72.      
  73.      gdc->Admin        = STRnew();
  74.      gdc->AdminEmail   = STRnew();
  75.  
  76.      gdc->Site         = STRnew();
  77.      gdc->Org          = STRnew();
  78.      gdc->Geog         = STRnew();
  79.      gdc->Loc          = STRnew();
  80.      gdc->Lang         = STRnew();
  81.      gdc->TZ           = 0;
  82.  
  83.      gdc->Tixfile      = STRnew();
  84.  
  85.      STRset(gdc->Logfile, "");
  86.      STRset(gdc->BummerMsg, "");
  87.      STRset(gdc->Hostname, "");
  88.  
  89.      return(gdc);
  90. }
  91.  
  92. void
  93. GDCdestroy(gdc)
  94.   GDCobj *gdc;
  95. {
  96.      EXAdestroy(gdc->Extensions);
  97.      SiteArrDestroy(gdc->Sites);
  98.  
  99.      STRdestroy(gdc->Logfile);
  100.      STRdestroy(gdc->BummerMsg);
  101.      STRdestroy(gdc->Hostname);
  102.      STRdestroy(gdc->Lang);
  103.      STRdestroy(gdc->Tixfile);
  104.      /** etc..**/
  105.  
  106.      free(gdc);
  107. }
  108.  
  109.  
  110. /*
  111.  * Parse Gopherd.conf tokens..
  112.  */
  113.  
  114. static
  115. boolean
  116. GDCtokens(gdc, token, rest)
  117.   GDCobj *gdc;
  118.   char *token;
  119.   char *rest;
  120. {
  121.      boolean success = TRUE;
  122.  
  123.      if (DEBUG) 
  124.       printf("Parsed token '%s', rest of line '%s'\n", token, rest);
  125.      
  126.      if (strcasecmp(token, "ACCESS") == 0) {
  127.       int moo;
  128.       success = SiteProcessLine(gdc->Sites, rest, gdc->Defaccess);
  129.       moo = SiteAccess(gdc->Sites, "default");
  130.       if (moo != ACC_UNKNOWN)
  131.            gdc->Defaccess = moo;
  132.  
  133.       gdc->Securityon = TRUE;
  134.      }
  135.  
  136.      else if (strcasecmp(token, "ADMIN")==0)
  137.       GDCsetAdmin(gdc, rest);
  138.      else if (strcasecmp(token, "ADMINEMAIL")==0)
  139.       GDCsetAdminEmail(gdc, rest);
  140.      else if (strcasecmp(token, "HOSTALIAS")==0)
  141.       GDCsetHostname(gdc, rest);
  142.      else if (strcasecmp(token, "SITE")==0)
  143.       GDCsetSite(gdc, rest);
  144.      else if (strcasecmp(token, "ORG")==0)
  145.       GDCsetOrg(gdc, rest);
  146.      else if (strcasecmp(token, "LOC")==0)
  147.       GDCsetLoc(gdc, rest);
  148.      else if (strcasecmp(token, "LOGFILE")==0)
  149.       GDCsetLogfile(gdc, rest);
  150.      else if (strcasecmp(token, "GEOG")==0)
  151.       GDCsetGeog(gdc, rest);
  152.      else if (strcasecmp(token, "BUMMERMSG")==0)
  153.       GDCsetBummerMsg(gdc, rest);
  154.      else if (strcasecmp(token, "LANGUAGE")==0) {
  155.       rest = skip_whitespace(rest);
  156.       GDCsetLang(gdc, rest);
  157.      }
  158.      else if (strcasecmp(token, "VIEWEXT")==0) {
  159.       success = EXAprocessLine(gdc->Extensions, EXT_VIEW, rest, GDCgetLang(gdc));
  160.      }
  161.      else if (strcasecmp(token, "BLOCKEXT")==0) {
  162.       success = EXAprocessLine(gdc->Extensions, EXT_BLOCK, rest, NULL);
  163.      }
  164.      else if (strcasecmp(token, "BLOCKREFEXT")==0) {
  165.       success = EXAprocessLine(gdc->Extensions, EXT_BLOCKREF, rest, NULL);
  166.      }
  167.      else if (strcasecmp(token, "IGNORE")==0) {
  168.       success = EXAprocessLine(gdc->Extensions, EXT_IGNORE, rest, NULL);
  169.      }
  170.      else if (strcasecmp(token, "SECUREUSERS")==0) {
  171.       GDCsetTixfile(gdc, rest);
  172.       /*** Try to open the file ***/
  173.       /*** TODO ***/
  174.       ;
  175.      }
  176.      else
  177.       success = FALSE;
  178.      
  179.      return(success);
  180. }
  181.  
  182. void
  183. GDCfromFile(gdc, filename)
  184.   GDCobj *gdc;
  185.   char *filename;
  186. {
  187.      FILE *gdcfile;
  188.      char inputline[256];
  189.      char *cp, *token, *restofline;
  190.      boolean success;
  191.  
  192.  
  193.      if ((gdcfile = fopen(filename, "r")) == (FILE *) NULL) {
  194.       printf("Cannot open file '%s'\n", filename);
  195.       exit(-1);
  196.      }
  197.  
  198.      while (fgets(inputline, sizeof inputline, gdcfile)!= NULL) {
  199.       ZapCRLF(inputline);
  200.       
  201.       if (*inputline == '#' || *inputline == '\0') /** Ignore comments **/
  202.            continue;
  203.  
  204.       cp = strchr(inputline, ':');
  205.       if (cp == NULL) {
  206.            fprintf(stderr, "Bad line '%s'\n", inputline);
  207.            exit(-1);
  208.       }
  209.       *cp = '\0';
  210.       token      = inputline;
  211.       restofline = cp+1;
  212.       while (*restofline == ' ' || *restofline == '\t')
  213.            restofline++;
  214.       
  215.       success = GDCtokens(gdc, token, restofline);
  216.       if (!success) {
  217.            fprintf(stderr, "Bad line '%s'\n", inputline);
  218.            exit(-1);
  219.       }
  220.      }
  221.      
  222.      fclose(gdcfile);
  223. }
  224.  
  225.  
  226. boolean GDCCanSearch(gdc, hostname, ipnum)
  227.   GDCobj *gdc;
  228.   char *hostname, *ipnum;
  229. {
  230.      boolean test;
  231.  
  232.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  233.  
  234.      if (gdc->Securityon == FALSE)
  235.       return(TRUE);
  236.  
  237.      if ((test = SiteArrCanSearch(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  238.       return(test);
  239.      
  240.      if ((gdc->Defaccess & ACC_SEARCH) == ACC_SEARCH)
  241.       return(TRUE);
  242.      else
  243.       return(FALSE);
  244.  
  245. }
  246.  
  247. boolean GDCCanRead(gdc, hostname, ipnum)
  248.   GDCobj *gdc;
  249.   char *hostname, *ipnum;
  250. {
  251.      boolean test;
  252.  
  253.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  254.  
  255.      if (gdc->Securityon == FALSE)
  256.       return(TRUE);
  257.  
  258.      if ((test = SiteArrCanRead(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  259.       return(test);
  260.      
  261.      if ((gdc->Defaccess & ACC_READ) == ACC_READ)
  262.       return(TRUE);
  263.      else
  264.       return(FALSE);
  265.  
  266. }
  267.  
  268.  
  269. boolean GDCCanBrowse(gdc, hostname, ipnum)
  270.   GDCobj *gdc;
  271.   char *hostname, *ipnum;
  272. {
  273.      boolean test;
  274.  
  275.      if (DEBUG) printf("Testing %s/%s for access\n", hostname, ipnum);
  276.  
  277.      if (gdc->Securityon == FALSE)
  278.       return(TRUE);
  279.  
  280.      if ((test = SiteArrCanBrowse(gdc->Sites, hostname, ipnum)) != ACC_UNKNOWN)
  281.       return(test);
  282.      
  283.      if ((gdc->Defaccess & ACC_BROWSE) == ACC_BROWSE)
  284.       return(TRUE);
  285.      else
  286.       return(FALSE);
  287.  
  288. }
  289.  
  290.  
  291. /** Is this file ignored? **/
  292. boolean
  293. GDCignore(gdc, fname)
  294.   GDCobj *gdc;
  295.   char *fname;
  296. {
  297.      Extobj *ext;
  298.  
  299.      ext = EXnew();
  300.  
  301.      if (EXAsearch(gdc->Extensions, ext, fname, EXT_IGNORE)) {
  302.       EXdestroy(ext);
  303.       return(TRUE);
  304.      }
  305.      else
  306.       EXdestroy(ext);
  307.       return(FALSE);
  308.  
  309. }
  310.  
  311.  
  312. boolean 
  313. GDCViewExtension(gdc, fext, extin)
  314.   GDCobj *gdc;
  315.   char *fext;
  316.   Extobj **extin;
  317. {
  318.      Extobj *ext;
  319.      char *gplustype;
  320.      
  321.      ext = EXnew();
  322.  
  323.      if (EXAsearch(gdc->Extensions, ext, fext, EXT_VIEW)) {
  324.       *extin = ext;
  325.       return(TRUE);
  326.      }
  327.      else
  328.       return(FALSE);
  329.  
  330. }
  331.  
  332.  
  333. boolean 
  334. GDCBlockExtension(gdc, fext, ext)
  335.   GDCobj *gdc;
  336.   char *fext;
  337.   Extobj *ext;
  338. {
  339.  
  340.      if (EXAsearch(gdc->Extensions, ext, fext, EXT_BLOCK)) {
  341.       return(TRUE);
  342.      }
  343.      else
  344.       return(FALSE);
  345. }
  346.