cgi_log.c

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /* cgi_util.c © Copyright 2002-2005 by Raosoft Inc. All Rights Reserved.      */
00003 /*                                                                            */
00004 /* You may use and modify this file for your own use, but may not distribute  */
00005 /* it or derivative works without the prior written consent of Raosoft, Inc.  */
00006 /*                                                                            */
00007 /* If you choose to share your modifications with Raosoft, Inc. the company   */
00008 /* will attempt to incorporate them into future versions of this file.        */
00009 /*                                                                            */
00010 /* This software is provided "as is," and Raosoft makes no warranty, express  */
00011 /* or implied, of fitness for a particular application. Every measure has been*/
00012 /* taken to anticipate risks inherent to computer networks, but we cannot     */
00013 /* guarantee safety or reliability of this program in every situation.        */
00014 /*                                                                            */
00015 /******************************************************************************/
00016 
00017 #include "cgi.h"
00018 /* Log startup conditions */
00019 
00020 
00021 #if defined(CGI_FAST)
00022 void LogError(char * c)
00023 {}
00024 
00025 void LogMessage(char * c)
00026 {}
00027 
00028 void LogStartup(STREAM htmlout,char* argv0)
00029 {}
00030 
00031 void LogTrx(CGINameValue* data)
00032 {}
00033 
00034 void SetLoggingLevel(int i)
00035 {}
00036 #elif defined(VPWSCGI)
00037 void LogStartup(STREAM htmlout,char* argv0)
00038 {}
00039 
00040 void LogTrx(CGINameValue* data)
00041 {}
00042 
00043 void SetLoggingLevel(int i)
00044 {}
00045 void LogError(char * c)
00046 {
00047   LogMessage(c);
00048 }
00049 #else
00050 int CGILogLevel=0;
00051 /* 0=quiet, 1=log entries, 2=verbose, 4=startup */
00052 
00053 void SetLoggingLevel(int i)
00054  {CGILogLevel = i;}
00055 
00056 /* For use in debugging */
00057 void LogError(char * c)
00058  {
00059   FILE * h;
00060   h = CGIFOPEN("logerr.txt","at");
00061   if (h)
00062   {
00063    if (c) fputs(c,h);
00064    else fputs("*NULL*",h);
00065    CGIFCLOSE(h);
00066   }
00067  }
00068 
00069 void LogMessage(char * c)
00070  {
00071   FILE * h;
00072   if (CGILogLevel < 1) return;
00073   h = CGIFOPEN("logmsg.txt","at");
00074   if (h)
00075   {
00076    if (c) fputs(c,h);
00077    else fputs("*NULL*",h);
00078    CGIFCLOSE(h);
00079   }
00080  }
00081 
00082 static char* CGIHeaders[] =
00083 {
00084  "DOCUMENT_ROOT",
00085  "GATEWAY_INTERFACE",
00086  "HTTP_ACCEPT",
00087  "HTTP_ACCEPT_CHARSET",
00088  "HTTP_ACCEPT_ENCODING",
00089  "HTTP_ACCEPT_LANGUAGE",
00090  "HTTP_CONNECTION",
00091  "HTTP_COOKIE",
00092  "HTTP_ADDR",
00093  "HTTP_HOST",
00094  "HTTP_USER_AGENT",
00095  "REMOTE_ADDR",
00096  "REMOTE_HOST",
00097  "IFS",
00098  "MAILCHECK",
00099  "PATH",
00100  "QUERY_STRING",
00101  "REMOTE_ADDR",
00102  "REMOTE_HOST",
00103  "REMOTE_PORT",
00104  "REQUEST_METHOD",
00105  "REQUEST_URI",
00106  "SCRIPT_FILENAME",
00107  "SCRIPT_NAME",
00108  "SCRIPT_URI",
00109  "SCRIPT_URL",
00110  "SERVER_ADMIN",
00111  "SERVER_NAME",
00112  "SERVER_PORT",
00113  "SERVER_PROTOCOL",
00114  "SERVER_SOFTWARE",
00115  0
00116 };
00117 
00118 
00119 void LogStartup(STREAM htmlout,char* argv0)
00120 {
00121  FILE * h;
00122  int i;
00123  char fn[MAXPATH];
00124  CGINameValue* m;
00125 
00126  ExpandLocalPath(argv0,fn,"cgi.ini","");
00127 
00128  m = ReadINIFileSection(fn, "admin",0);
00129 
00130  if (m != NULL)
00131  {
00132   if (GetField(m,"LOGLEVEL"))
00133   {
00134    SetLoggingLevel(atoi(GetFieldValue(m,"LOGLEVEL")));
00135   }
00136   DeleteNVP(m);
00137  }
00138 
00139  if (CGILogLevel < 3) return;
00140  h = CGIFOPEN("logenv.txt","at");
00141  if (!h) return;
00142  fprintf(h,"Starting %s\n",argv0);
00143  fprintf(h,"Environment:\n");
00144 
00145  for(i=0; CGIHeaders[i]; i++)
00146  {
00147   char* y = GetEnvironment(htmlout,CGIHeaders[i]);
00148   if (y) fprintf(h,"%s=%s\n",CGIHeaders[i],y);
00149  }
00150  fprintf(h,"\n\n");
00151  CGIFCLOSE(h);
00152 }
00153 
00154 void LogTrx(CGINameValue* data)
00155 {
00156  int i;
00157  FILE * h;
00158  if (CGILogLevel < 2) return;
00159  h = CGIFOPEN("logtrx.txt","at");
00160  if (h)
00161   {
00162    for (i=0;data[i].name;i++)
00163    {
00164     if (!data[i].name[0]) continue;
00165     fprintf(h,"%s=%s\n",data[i].name,data[i].value);
00166    }
00167    fputs("\n",h);
00168    CGIFCLOSE(h);
00169   }
00170 }
00171 #endif


Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/