Documentation Source Text
Check-in [93ba1a8d9d]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:93ba1a8d9d8c5ac79157d182c45bd14d712d32a4
Date: 2013-07-15 17:11:37
User: drh
Comment:The log file for althttpd is now RFC-4180 CSV. Cherry-pick merge from check-in 52bfa21f48e14a29.
Tags And Properties
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to misc/althttpd.c

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163






164
165
166
167
168
169
170
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
199
200
201
202
203
204
205
206


















207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
...
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
static int useHttps = 0;         /* True to use HTTPS: instead of HTTP: */
static char *zHttp = "http";     /* http or https */
static int useTimeout = 1;       /* True to use times */
static int ipv6Only = 0;         /* Use IPv6 only */
static int ipv4Only = 0;         /* Use IPv4 only */

/*
** Change every space or unprintable character in the zAgent[] string
** into an _.
**
** If the user agent string contains certain prohibited string, then
** exit immediately.
*/
static void FixupUserAgent(void){
  int i;
  if( zAgent==0 || zAgent[0]==0 ) zAgent = "*";
  for(i=0; zAgent[i]; i++){
    int c = zAgent[i];
    if( c<'!' || c>'~'  ){ zAgent[i] = '_'; }
  }






}

/*
** Make an entry in the log file.  If the HTTP connection should be
** closed, then terminate this process.  Otherwise return.
*/
static void MakeLogEntry(int a){
................................................................................
  if( zTmpNam ){
    unlink(zTmpNam);
  }
  if( zLogFile && !omitLog ){
    time_t now;
    struct tm *pTm;
    struct rusage self, children;
    int i;
    int waitStatus;
    char zDate[200];
    char *zRM = zRemoteUser ? zRemoteUser : "*";

    if( zScript==0 || zScript[0]==0 ) zScript = "*";
    if( zRemoteAddr==0 || zRemoteAddr[0]==0 ) zRemoteAddr = "*";
    if( zHttpHost==0 || zHttpHost[0]==0 ) zHttpHost = "*";
    if( zReferer==0 || zReferer[0]==0 ) zReferer = "*";
    for(i=0; zReferer[i]; i++){ 
      if( isspace(zReferer[i]) ){ zReferer = "*"; break; }
    }
    if( zAgent==0 || zAgent[0]==0 ) zAgent = "*";
    time(&now);
    pTm = localtime(&now);
    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
    waitpid(-1, &waitStatus, WNOHANG);
    getrusage(RUSAGE_SELF, &self);
    getrusage(RUSAGE_CHILDREN, &children);
    if( (log = fopen(zLogFile,"a"))!=0 ){
................................................................................
#ifdef COMBINED_LOG_FORMAT
      strftime(zDate, sizeof(zDate), "%d/%b/%Y:%H:%M:%S %z", pTm);
      fprintf(log, "%s - - [%s] \"%s %s %s\" %s %d \"%s\" \"%s\"\n",
              zRemoteAddr, zDate, zMethod, zScript, zProtocol,
              zReplyStatus, nOut, zReferer, zAgent);
#else
      strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
      fprintf(log, "%s %s %s://%s%s %s %s %d %d %d %d %d %d %d %d %s %s\n", 


















          zDate, zRemoteAddr, zHttp, zHttpHost, zScript, zReferer,
          zReplyStatus, nIn, nOut,
          (int)(self.ru_utime.tv_sec*1000000 + self.ru_utime.tv_usec),
          (int)(self.ru_stime.tv_sec*1000000 + self.ru_stime.tv_usec),
          (int)(children.ru_utime.tv_sec*1000000 + children.ru_utime.tv_usec),
          (int)(children.ru_stime.tv_sec*1000000 + children.ru_stime.tv_usec),
          (int)(now - beginTime),
          nRequest, zAgent, zRM

      );
#endif
      fclose(log);
      nIn = nOut = 0;
    }
  }
  if( closeConnection ){
................................................................................

    nIn += strlen(zLine);
    zFieldName = GetFirstElement(zLine,&zVal);
    if( zFieldName==0 || *zFieldName==0 ) break;
    RemoveNewline(zVal);
    if( strcasecmp(zFieldName,"User-Agent:")==0 ){
      zAgent = StrDup(zVal);
      FixupUserAgent();
    }else if( strcasecmp(zFieldName,"Accept:")==0 ){
      zAccept = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Content-length:")==0 ){
      zContentLength = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Content-type:")==0 ){
      zContentType = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Referer:")==0 ){







|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>







 







<


|

|
|
|
|
<
<
<
|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
<
>







 







<







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192



193
194
195
196
197
198
199
200
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
...
961
962
963
964
965
966
967

968
969
970
971
972
973
974
static int useHttps = 0;         /* True to use HTTPS: instead of HTTP: */
static char *zHttp = "http";     /* http or https */
static int useTimeout = 1;       /* True to use times */
static int ipv6Only = 0;         /* Use IPv6 only */
static int ipv4Only = 0;         /* Use IPv4 only */

/*
** Double any double-quote characters in a string.
*/
static char *Escape(char *z){
  int i, j;
  int n;
  char c;
  char *zOut;
  for(i=0; (c=z[i])!=0 && c!='"'; i++){}
  if( c==0 ) return z;
  n = 1;
  for(i++; (c=z[i])!=0; i++){ if( c=='"' ) n++; }
  zOut = malloc( i+n+1 );
  if( zOut==0 ) return "";
  for(i=j=0; (c=z[i])!=0; i++){
    zOut[j++] = c;
    if( c=='"' ) zOut[j++] = c;
  }
  zOut[j] = 0;
  return zOut;
}

/*
** Make an entry in the log file.  If the HTTP connection should be
** closed, then terminate this process.  Otherwise return.
*/
static void MakeLogEntry(int a){
................................................................................
  if( zTmpNam ){
    unlink(zTmpNam);
  }
  if( zLogFile && !omitLog ){
    time_t now;
    struct tm *pTm;
    struct rusage self, children;

    int waitStatus;
    char zDate[200];
    char *zRM = zRemoteUser ? zRemoteUser : "";

    if( zScript==0 || zScript[0]==0 ) zScript = "";
    if( zRemoteAddr==0 || zRemoteAddr[0]==0 ) zRemoteAddr = "";
    if( zHttpHost==0 || zHttpHost[0]==0 ) zHttpHost = "";
    if( zReferer==0 || zReferer[0]==0 ) zReferer = "";



    if( zAgent==0 || zAgent[0]==0 ) zAgent = "";
    time(&now);
    pTm = localtime(&now);
    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
    waitpid(-1, &waitStatus, WNOHANG);
    getrusage(RUSAGE_SELF, &self);
    getrusage(RUSAGE_CHILDREN, &children);
    if( (log = fopen(zLogFile,"a"))!=0 ){
................................................................................
#ifdef COMBINED_LOG_FORMAT
      strftime(zDate, sizeof(zDate), "%d/%b/%Y:%H:%M:%S %z", pTm);
      fprintf(log, "%s - - [%s] \"%s %s %s\" %s %d \"%s\" \"%s\"\n",
              zRemoteAddr, zDate, zMethod, zScript, zProtocol,
              zReplyStatus, nOut, zReferer, zAgent);
#else
      strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
      /* Log record files:
      **  (1) Date and time
      **  (2) IP address
      **  (3) URL being accessed
      **  (4) Referer
      **  (5) Reply status
      **  (6) Bytes received
      **  (7) Bytes sent
      **  (8) Self user time
      **  (9) Self system time
      ** (10) Children user time
      ** (11) Children system time
      ** (12) Total wall-clock time
      *  (13) Request number for same TCP/IP connection
      ** (14) User agent
      ** (15) Remote user
      */
      fprintf(log,
        "%s,%s,\"%s://%s%s\",\"%s\",%s,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\"\n",
        zDate, zRemoteAddr, zHttp, Escape(zHttpHost), Escape(zScript),
        Escape(zReferer), zReplyStatus, nIn, nOut,
        (int)(self.ru_utime.tv_sec*1000000 + self.ru_utime.tv_usec),
        (int)(self.ru_stime.tv_sec*1000000 + self.ru_stime.tv_usec),
        (int)(children.ru_utime.tv_sec*1000000 + children.ru_utime.tv_usec),
        (int)(children.ru_stime.tv_sec*1000000 + children.ru_stime.tv_usec),
        (int)(now - beginTime),

        nRequest, Escape(zAgent), Escape(zRM)
      );
#endif
      fclose(log);
      nIn = nOut = 0;
    }
  }
  if( closeConnection ){
................................................................................

    nIn += strlen(zLine);
    zFieldName = GetFirstElement(zLine,&zVal);
    if( zFieldName==0 || *zFieldName==0 ) break;
    RemoveNewline(zVal);
    if( strcasecmp(zFieldName,"User-Agent:")==0 ){
      zAgent = StrDup(zVal);

    }else if( strcasecmp(zFieldName,"Accept:")==0 ){
      zAccept = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Content-length:")==0 ){
      zContentLength = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Content-type:")==0 ){
      zContentType = StrDup(zVal);
    }else if( strcasecmp(zFieldName,"Referer:")==0 ){