jkOwnLib/gfWebLib.c

Go to the documentation of this file.
00001 /* gfWebLib - some helper routines for the webBlat and webPcr.
00002  * Copyright 2004-2005 Jim Kent.  All rights reserved. */
00003 #include "common.h"
00004 #include "linefile.h"
00005 #include "hash.h"
00006 #include "cheapcgi.h"
00007 #include "gfWebLib.h"
00008 
00009 
00010 struct gfServerAt *gfWebFindServer(struct gfServerAt *serverList, char *varName)
00011 /* Find active server (that matches contents of CGI variable varName). */
00012 {
00013 struct gfServerAt *server = serverList;
00014 if (cgiVarExists(varName))
00015      {
00016      char *db = cgiString(varName);
00017      for (server = serverList; server != NULL; server = server->next)
00018           {
00019           if (sameString(db, server->name))
00020               break;
00021           }
00022      if (server == NULL)
00023           errAbort("%s %s not found", varName, db);
00024      }
00025 return server;
00026 }
00027 
00028 struct gfWebConfig *gfWebConfigRead(char *fileName)
00029 /* Read configuration file into globals. */
00030 {
00031 struct gfWebConfig *cfg;
00032 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00033 char *line, *word;
00034 struct hash *uniqHash = newHash(0), *uniqTransHash = newHash(0), *hash;
00035 
00036 AllocVar(cfg);
00037 cfg->company = "";
00038 while (lineFileNextReal(lf, &line))
00039     {
00040     word = nextWord(&line);
00041     if (sameWord("company", word))
00042         {
00043         cfg->company = cloneString(trimSpaces(line));
00044         }
00045     else if (sameWord("gfServer", word) || sameWord("gfServerTrans", word))
00046         {
00047         struct gfServerAt *server;
00048         char *dupe = cloneString(line);
00049         AllocVar(server);
00050         server->host = nextWord(&dupe);
00051         server->port = nextWord(&dupe);
00052         server->seqDir = nextWord(&dupe);
00053         server->name = trimSpaces(dupe);
00054         if (server->name == NULL || server->name[0] == 0)
00055             errAbort("Badly formed gfServer command line %d of %s:\n%s",
00056                 lf->lineIx, fileName, line);
00057         if (sameString("gfServerTrans", word))
00058             {
00059             slAddTail(&cfg->transServerList, server);
00060             hash = uniqTransHash;
00061             }
00062         else
00063             {
00064             slAddTail(&cfg->serverList, server);
00065             hash = uniqHash;
00066             }
00067         if (hashLookup(hash, server->name))
00068             errAbort("Duplicate %s name %s line %d of %s",
00069                 word, server->name, lf->lineIx, fileName);
00070         hashAdd(hash, server->name, NULL);
00071         }
00072     else if (sameWord("tempDir", word))
00073         {
00074         cfg->tempDir = cloneString(trimSpaces(line));
00075         }
00076     else if (sameWord("background", word))
00077         {
00078         cfg->background = cloneString(trimSpaces(line));
00079         }
00080     else
00081         {
00082         errAbort("Unrecognized command %s line %d of  %s", word, lf->lineIx, fileName);
00083         }
00084     }
00085 
00086 if (cfg->serverList == NULL && cfg->transServerList == NULL)
00087     errAbort("no gfServer's specified in %s", fileName);
00088 freeHash(&uniqHash);
00089 freeHash(&uniqTransHash);
00090 return cfg;
00091 }
00092 

Generated on Tue Dec 25 18:39:30 2007 for blat by  doxygen 1.5.2