lib/portimpl.c

Go to the documentation of this file.
00001 /* Implementation file for some portability stuff mostly aimed
00002  * at making the same code run under different web servers.
00003  *
00004  * This file is copyright 2002 Jim Kent, but license is hereby
00005  * granted for all use - public, private or commercial. */
00006 
00007 #include "common.h"
00008 #include "htmshell.h"
00009 #include "portable.h"
00010 #include "obscure.h"
00011 #include "portimpl.h"
00012 #include <dirent.h>
00013 
00014 static char const rcsid[] = "$Id: portimpl.c,v 1.14 2006/06/23 21:44:04 hiram Exp $";
00015 
00016 static struct webServerSpecific *wss = NULL;
00017 
00018 static void setupWss()
00019 {
00020 if (wss == NULL)
00021     {
00022     char *s = getenv("SERVER_SOFTWARE");
00023     wss = &wssDefault;
00024     if (s == NULL)
00025         {
00026         wss = &wssCommandLine;
00027         }
00028     else
00029         {
00030         if (strncmp(wssMicrosoftII.name, s, strlen(wssMicrosoftII.name)) == 0)
00031             wss = &wssMicrosoftII;
00032         else if (strncmp(wssMicrosoftPWS.name, s, strlen(wssMicrosoftPWS.name)) == 0)
00033             wss = &wssMicrosoftPWS;
00034         else 
00035             {
00036             char *t = getenv("HTTP_HOST");
00037             if (t != NULL)
00038                 {
00039                 if (sameWord(t, "Crunx"))
00040                     wss = &wssLinux;
00041                 else if (endsWith(t, "brc.mcw.edu"))
00042                     wss = &wssBrcMcw;
00043                 }
00044             }
00045         }
00046     }
00047 }
00048 
00049 void makeTempName(struct tempName *tn, char *base, char *suffix)
00050 /* Figure out a temp name, and how CGI and HTML will access it. */
00051 {
00052 setupWss();
00053 wss->makeTempName(tn,base,suffix);
00054 }
00055 
00056 char *cgiDir()
00057 {
00058 setupWss();
00059 return wss->cgiDir();
00060 }
00061 
00062 char *trashDir()
00063 /* Return the relative path to trash directory for CGI binaries */
00064 {
00065 setupWss();
00066 return wss->trashDir();
00067 }
00068 
00069 double machineSpeed()
00070 /* Return relative speed of machine.  UCSC CSE dept. 1999 web server is 1.0 */
00071 {
00072 setupWss();
00073 return wss->speed();
00074 }
00075 
00076 void envUpdate(char *name, char *value)
00077 /* Update an environment string */
00078 {
00079 int size = strlen(name) + strlen(value) + 2;
00080 char *s = needMem(size);
00081 safef(s, size, "%s=%s", name, value);
00082 putenv(s);
00083 }
00084 
00085 void mkdirTrashDirectory(char *prefix)
00086 /*      create the specified trash directory if it doesn't exist */
00087 {
00088 struct stat buf;
00089 char trashDirName[128];
00090 safef(trashDirName, sizeof(trashDirName), "%s/%s", trashDir(), prefix);
00091 if (stat(trashDirName,&buf))
00092     {
00093     int result = mkdir (trashDirName, S_IRWXU | S_IRWXG | S_IRWXO);
00094     if (0 != result)
00095         errnoAbort("failed to create directory %s", trashDirName);
00096     }
00097 }

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