httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roy T. Fielding" <field...@avron.ICS.UCI.EDU>
Subject three part patch for other enhancements
Date Tue, 28 Feb 1995 04:49:44 GMT
I sent these in a couple weeks ago.  They may be of interest, maybe not.
I am off to Ohio for the rest of the week, so I figured it would be best
to just show them to everybody now.

These patches include two fixes and one enhancement:

    1) http_dir is fixed so that the Parent Directory links
       are always given a trailing slash.  This reduces unnecessary
       redirects.

    2) http_log is fixed so that writes to the access_log are not
       performed via stdio, and thus are guaranteed to be atomic 
       actions.  This fixes the problem of log entries being overwritten
       by simultaneous fprintf's.

    3) http_log and http_mime are modified to record the User Agent
       and Referer so that they can be logged on errors.  NOTE: no attempt
       was made to make this change efficient.

Cheers,

_...Roy T. Fielding                                 (fielding@ics.uci.edu)   
    Department of Information & Computer Science       tel:+1(714)824-4049
    University of California, Irvine, CA 92717-3425    fax:+1(714)824-4056
    http://www.ics.uci.edu/dir/grad/Software/fielding
==========================================================================
*** save/http_log.c	Sat May  7 20:37:50 1994
--- http_log.c	Sun Feb  5 01:31:05 1995
***************
*** 3,15 ****
   * 
   * Rob McCool
   * 
   */
  
  
  #include "httpd.h"
  
  FILE *error_log;
! static FILE *xfer_log;
  
  void open_logs() {
      if(!(error_log = fopen(error_fname,"a"))) {
--- 3,23 ----
   * 
   * Rob McCool
   * 
+  * Modified by Roy Fielding to use open() and write() instead of
+  * fopen() and fprintf(), thus enabling atomic appends to xfer_log.
+  * Also added logging of User-Agent and Referer on errors.
   */
  
  
  #include "httpd.h"
  
+ extern char useragent[];
+ extern char referer[];
+ 
  FILE *error_log;
! static int xfer_log;
! static int xfer_flags = ( O_WRONLY | O_APPEND | O_CREAT );
! static mode_t xfer_mode = ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
  
  void open_logs() {
      if(!(error_log = fopen(error_fname,"a"))) {
***************
*** 18,33 ****
          perror("fopen");
          exit(1);
      }
!     if(!(xfer_log = fopen(xfer_fname,"a"))) {
          fprintf(stderr,"httpd: could not open transfer log file %s.\n",
                  xfer_fname);
!         perror("fopen");
          exit(1);
      }
  }
  
  void close_logs() {
!     fclose(xfer_log);
      fclose(error_log);
  }
  
--- 26,41 ----
          perror("fopen");
          exit(1);
      }
!     if((xfer_log = open(xfer_fname,xfer_flags,xfer_mode)) < 0) {
          fprintf(stderr,"httpd: could not open transfer log file %s.\n",
                  xfer_fname);
!         perror("open");
          exit(1);
      }
  }
  
  void close_logs() {
!     close(xfer_log);
      fclose(error_log);
  }
  
***************
*** 86,105 ****
          strcat(str,"- ");
  
      if(bytes_sent != -1)
!         sprintf(str,"%s%d",str,bytes_sent);
      else
!         strcat(str,"- ");
!     fprintf(xfer_log,"%s\n",str);
!     fclose(xfer_log);
  }
  
  void log_error(char *err) {
      fprintf(error_log, "[%s] %s\n",get_time(),err);
      fclose(error_log);
  }
  
  void log_error_noclose(char *err) {
      fprintf(error_log, "[%s] %s\n",get_time(),err);
      fflush(error_log);
  }
  
--- 94,122 ----
          strcat(str,"- ");
  
      if(bytes_sent != -1)
!         sprintf(str,"%s%d\n",str,bytes_sent);
      else
!         strcat(str,"-\n");
! 
!     write(xfer_log,str,strlen(str));
!     close(xfer_log);
  }
  
  void log_error(char *err) {
      fprintf(error_log, "[%s] %s\n",get_time(),err);
+     if(useragent[0])
+         fprintf(error_log,"    User-Agent: %s\n",useragent);
+     if(referer[0])
+         fprintf(error_log,"    Referer: %s\n",referer);
      fclose(error_log);
  }
  
  void log_error_noclose(char *err) {
      fprintf(error_log, "[%s] %s\n",get_time(),err);
+     if(useragent[0])
+         fprintf(error_log,"    User-Agent: %s\n",useragent);
+     if(referer[0])
+         fprintf(error_log,"    Referer: %s\n",referer);
      fflush(error_log);
  }
  
*** save/http_mime.c	Sat May  7 19:47:08 1994
--- http_mime.c	Sun Feb  5 01:11:54 1995
***************
*** 37,43 ****
  char *out_headers;
  char **in_headers_env;
  char *status_line;
! char ims[MAX_STRING_LEN]; /* If-modified-since */
  
  
  void hash_insert(struct mime_ext *me) {
--- 37,45 ----
  char *out_headers;
  char **in_headers_env;
  char *status_line;
! char ims[MAX_STRING_LEN];       /* If-modified-since */
! char useragent[MAX_STRING_LEN]; /* User-Agent */
! char referer[MAX_STRING_LEN];   /* Referer */
  
  
  void hash_insert(struct mime_ext *me) {
***************
*** 389,395 ****
              sscanf(l,"%d",&content_length);
              continue;
          }
!         if(!strcasecmp(w,"If-modified-since"))
              strcpy(ims,l);
  
          http2cgi(w);
--- 391,401 ----
              sscanf(l,"%d",&content_length);
              continue;
          }
!         if(!strcasecmp(w,"User-Agent"))
!             strcpy(useragent,l);
!         else if(!strcasecmp(w,"Referer"))
!             strcpy(referer,l);
!         else if(!strcasecmp(w,"If-modified-since"))
              strcpy(ims,l);
  
          http2cgi(w);
***************
*** 417,423 ****
  void dump_default_header(FILE *fd) {
      fprintf(fd,"Date: %s%c",gm_timestr_822(time(NULL)),LF);
      fprintf(fd,"Server: %s%c",SERVER_VERSION,LF);
-     fprintf(fd,"MIME-version: 1.0%c",LF);
  }
  
  void send_http_header(FILE *fd) {
--- 423,428 ----
*** save/http_dir.c	Sat May  7 20:02:07 1994
--- http_dir.c	Wed Jan 11 22:08:26 1995
***************
*** 495,501 ****
          
      for(x=0;x<n;x++) {
          if((!strcmp(ar[x]->name,"../")) || (!strcmp(ar[x]->name,".."))) {
!             make_full_path(name,"..",t);
              getparents(t);
              if(t[0] == '\0') {
                  t[0] = '/'; t[1] = '\0';
--- 495,501 ----
          
      for(x=0;x<n;x++) {
          if((!strcmp(ar[x]->name,"../")) || (!strcmp(ar[x]->name,".."))) {
!             make_full_path(name,"../",t);
              getparents(t);
              if(t[0] == '\0') {
                  t[0] = '/'; t[1] = '\0';

Mime
View raw message