httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sameer <sam...@c2.net>
Subject [No Subject]
Date Wed, 20 Nov 1996 02:03:29 GMT
Common subdirectories: src-bak/CVS and src/CVS
diff -C3 src-bak/alloc.c src/alloc.c
*** src-bak/alloc.c	Tue Nov 19 17:34:11 1996
--- src/alloc.c	Tue Nov 19 17:44:06 1996
***************
*** 988,993 ****
--- 988,1097 ----
    unblock_alarms();
    return pid;
  }
+ int spawn_child_err_buff (pool *p, void (*func)(void *), void *data,
+ 			  enum kill_conditions kill_how,
+ 			  BUFF **pipe_in, BUFF **pipe_out, BUFF **pipe_err)
+ {
+   int pid;
+   int in_fds[2];
+   int out_fds[2];
+   int err_fds[2];
+ 
+   block_alarms();
+   
+   if (pipe_in && pipe (in_fds) < 0)
+   {
+       unblock_alarms();
+       return 0;
+   }
+   
+   if (pipe_out && pipe (out_fds) < 0) {
+     if (pipe_in) {
+       close (in_fds[0]); close (in_fds[1]);
+     }
+     unblock_alarms();
+     return 0;
+   }
+ 
+   if (pipe_err && pipe (err_fds) < 0) {
+     if (pipe_in) {
+       close (in_fds[0]); close (in_fds[1]);
+     }
+     if (pipe_out) {
+       close (out_fds[0]); close (out_fds[1]);
+     }
+     unblock_alarms();
+     return 0;
+   }
+ 
+   if ((pid = fork()) < 0) {
+     if (pipe_in) {
+       close (in_fds[0]); close (in_fds[1]);
+     }
+     if (pipe_out) {
+       close (out_fds[0]); close (out_fds[1]);
+     }
+     if (pipe_err) {
+       close (err_fds[0]); close (err_fds[1]);
+     }
+     unblock_alarms();
+     return 0;
+   }
+ 
+   if (!pid) {
+     /* Child process */
+     
+     if (pipe_out) {
+       close (out_fds[0]);
+       dup2 (out_fds[1], STDOUT_FILENO);
+       close (out_fds[1]);
+     }
+ 
+     if (pipe_in) {
+       close (in_fds[1]);
+       dup2 (in_fds[0], STDIN_FILENO);
+       close (in_fds[0]);
+     }
+ 
+     if (pipe_err) {
+       close (err_fds[0]);
+       dup2 (err_fds[1], STDERR_FILENO);
+       close (err_fds[1]);
+     }
+ 
+     /* HP-UX SIGCHLD fix goes here, if someone will remind me what it is... */
+     signal (SIGCHLD, SIG_DFL);	/* Was that it? */
+     
+     func (data);
+     exit (0);			/* Should never get here... */
+   }
+ 
+   /* Parent process */
+ 
+   note_subprocess (p, pid, kill_how);
+   
+   if (pipe_out) {
+     close (out_fds[1]);
+     *pipe_out = fdopen (out_fds[0], "r");
+     *pipe_out = bcreate(p, B_RD);
+     bpushfd(*pipe_out, out_fds[0], out_fds[0]);
+   }
+ 
+   if (pipe_in) {
+     close (in_fds[0]);
+     *pipe_in = bcreate(p, B_WR);
+     bpushfd(*pipe_in, in_fds[1], in_fds[1]);
+   }
+ 
+   if (pipe_err) {
+     close (err_fds[1]);
+     *pipe_err = bcreate(p, B_RD);
+     bpushfd(*pipe_err, err_fds[0], err_fds[0]);
+   }
+ 
+   unblock_alarms();
+   return pid;
+ }
  
  static void free_proc_chain (struct process_chain *procs)
  {
Common subdirectories: src-bak/helpers and src/helpers
diff -C3 src-bak/http_protocol.c src/http_protocol.c
*** src-bak/http_protocol.c	Tue Nov 19 17:34:12 1996
--- src/http_protocol.c	Tue Nov 19 17:58:25 1996
***************
*** 1192,1197 ****
--- 1192,1261 ----
      return len_read;
  }
  
+ long send_fb(BUFF *fb, request_rec *r) { return send_fb_length(fb, r, -1); }
+ 
+ long send_fb_length(BUFF *fb, request_rec *r, long length)
+ {
+     char buf[IOBUFSIZE];
+     long total_bytes_sent;
+     register int n,o,w,len;
+     conn_rec *c = r->connection;
+     
+     if (length == 0) return 0;
+ 
+     total_bytes_sent = 0;
+ 
+     /* Clear out the buffer */
+     if(fb->incnt != 0)
+       {
+ 	int o;
+ 
+ 	o = bwrite(c->client, fb->inptr, fb->incnt);
+ 	fb->incnt -= o;
+ 	fb->inptr += o;
+       }
+     /* make unbuffered */
+     fb->flags &= ~B_RD;
+ 	
+     /* and make non-blocking */
+     fcntl(fb->fd_in, F_SETFL, O_NONBLOCK);
+ 
+     while(1)
+       {
+ 	fd_set fds;
+ 
+ 	bflush(c->client);
+ 
+ 
+ 	FD_ZERO(&fds);
+ 	FD_SET(fb->fd_in, &fds);
+ 	select(FD_SETSIZE, &fds, NULL, NULL, NULL); 
+       
+         while ((n= bread(fb, buf, IOBUFSIZE)) < 1
+ 	       && fb->flags & B_ERROR && errno == EINTR)
+ 	    continue;
+ 
+ 	if (n < 1) {
+             break;
+         }
+         o=0;
+ 	total_bytes_sent += n;
+ 	
+         while(n && !r->connection->aborted) {
+             w=bwrite(c->client, &buf[o], n);
+ 	    if(w <= 0)
+ 		break;
+ 	    reset_timeout(r); /* reset timeout after successfule write */
+             n-=w;
+             o+=w;
+         }
+     }
+     bflush(c->client);
+     
+     SET_BYTES_SENT(r);
+     return total_bytes_sent;
+ }
+ 
  long send_fd(FILE *f, request_rec *r) { return send_fd_length(f, r, -1); }
  
  long send_fd_length(FILE *f, request_rec *r, long length)
diff -C3 src-bak/mod_cgi.c src/mod_cgi.c
*** src-bak/mod_cgi.c	Tue Nov 19 17:34:13 1996
--- src/mod_cgi.c	Tue Nov 19 18:03:09 1996
***************
*** 341,347 ****
  {
      int retval, nph, dbpos = 0;
      char *argv0, *dbuf = NULL;
!     FILE *script_out, *script_in, *script_err;
      char argsbuffer[HUGE_STRING_LEN];
      int is_included = !strcmp (r->protocol, "INCLUDED");
      void *sconf = r->server->module_config;
--- 341,347 ----
  {
      int retval, nph, dbpos = 0;
      char *argv0, *dbuf = NULL;
!     BUFF *script_out, *script_in, *script_err;
      char argsbuffer[HUGE_STRING_LEN];
      int is_included = !strcmp (r->protocol, "INCLUDED");
      void *sconf = r->server->module_config;
***************
*** 389,401 ****
      cld.debug = conf->logname ? 1 : 0;
      
      if (!(child_pid =
! 	  spawn_child_err (r->connection->pool, cgi_child, (void *)&cld,
! 			   nph ? just_wait : kill_after_timeout,
  #ifdef __EMX__
! 			   &script_out, &script_in, &script_err))) {
  #else
! 			   &script_out, nph ? NULL : &script_in,
! 	    		   &script_err))) {
  #endif
          log_reason ("couldn't spawn child process", r->filename, r);
          return SERVER_ERROR;
--- 389,401 ----
      cld.debug = conf->logname ? 1 : 0;
      
      if (!(child_pid =
! 	  spawn_child_err_buff (r->connection->pool, cgi_child, (void *)&cld,
! 				nph ? just_wait : kill_after_timeout,
  #ifdef __EMX__
! 				&script_out, &script_in, &script_err))) {
  #else
!                                 &script_out, nph ? NULL : &script_in,
! 	    		        &script_err))) {
  #endif
          log_reason ("couldn't spawn child process", r->filename, r);
          return SERVER_ERROR;
***************
*** 424,430 ****
      
  	while ((len_read = get_client_block (r, argsbuffer, HUGE_STRING_LEN)))
  	{
! 	    if (fwrite (argsbuffer, 1, len_read, script_out) == 0)
  		break;
  	    if (conf->logname) {
  		if ((dbpos + len_read) > conf->bufbytes)
--- 424,430 ----
      
  	while ((len_read = get_client_block (r, argsbuffer, HUGE_STRING_LEN)))
  	{
! 	    if (bwrite (argsbuffer, 1, len_read, script_out) == 0)
  		break;
  	    if (conf->logname) {
  		if ((dbpos + len_read) > conf->bufbytes)
***************
*** 435,454 ****
  	    }
  	}
  
! 	fflush (script_out);
  	signal (SIGPIPE, handler);
  	
  	kill_timeout (r);
      }
      
!     pfclose (r->connection->pool, script_out);
      
      /* Handle script return... */
      if (script_in && !nph) {
          char *location, sbuf[MAX_STRING_LEN];
  	int ret;
        
!         if ((ret = scan_script_header_err(r, script_in, sbuf)))
  	    return log_script(r, conf, ret, dbuf, sbuf, script_in, script_err);
  	
  	location = table_get (r->headers_out, "Location");
--- 435,454 ----
  	    }
  	}
  
! 	bflush (script_out);
  	signal (SIGPIPE, handler);
  	
  	kill_timeout (r);
      }
      
!     bclose (script_out);
      
      /* Handle script return... */
      if (script_in && !nph) {
          char *location, sbuf[MAX_STRING_LEN];
  	int ret;
        
!         if ((ret = scan_script_header_err_buff(r, script_in, sbuf)))
  	    return log_script(r, conf, ret, dbuf, sbuf, script_in, script_err);
  	
  	location = table_get (r->headers_out, "Location");
***************
*** 457,465 ****
  	  
  	    /* Soak up all the script output */
  	    hard_timeout ("read from script", r);
! 	    while (fgets(argsbuffer, HUGE_STRING_LEN-1, script_in) != NULL)
  	        continue;
! 	    while (fgets(argsbuffer, HUGE_STRING_LEN-1, script_err) != NULL)
  	      continue;
  	    kill_timeout (r);
  
--- 457,465 ----
  	  
  	    /* Soak up all the script output */
  	    hard_timeout ("read from script", r);
! 	    while (bgets(argsbuffer, HUGE_STRING_LEN-1, script_in) != NULL)
  	        continue;
! 	    while (bgets(argsbuffer, HUGE_STRING_LEN-1, script_err) != NULL)
  	      continue;
  	    kill_timeout (r);
  
***************
*** 482,494 ****
  	
  	hard_timeout ("send script output", r);
  	send_http_header(r);
!         if(!r->header_only) send_fd (script_in, r);
  	/* Soak up stderr */
! 	while (fgets(argsbuffer, HUGE_STRING_LEN-1, script_err) != NULL)
  	  continue;
  	kill_timeout (r);
! 	pfclose (r->connection->pool, script_in);
! 	pfclose (r->connection->pool, script_err);
      }
  
      if (nph) {
--- 482,494 ----
  	
  	hard_timeout ("send script output", r);
  	send_http_header(r);
!         if(!r->header_only) send_fb (script_in, r);
  	/* Soak up stderr */
! 	while (bgets(argsbuffer, HUGE_STRING_LEN-1, script_err) != NULL)
  	  continue;
  	kill_timeout (r);
! 	bclose (script_in);
!         bclose (script_err);
      }
  
      if (nph) {
Common subdirectories: src-bak/modules and src/modules
Common subdirectories: src-bak/regex and src/regex
diff -C3 src-bak/util_script.c src/util_script.c
*** src-bak/util_script.c	Tue Nov 19 17:34:13 1996
--- src/util_script.c	Tue Nov 19 18:03:08 1996
***************
*** 259,264 ****
--- 259,347 ----
      }
  }
  
+ int scan_script_header_err_buff(request_rec *r, BUFF *fb, char *buffer)
+ {
+     char x[MAX_STRING_LEN];
+     char *w, *l;
+     int p;
+ 
+     if (buffer) *buffer = '\0';
+     w = buffer ? buffer : x;
+ 
+     hard_timeout ("read script header", r);
+     
+     while(1) {
+ 
+ 	if (bgets(w, MAX_STRING_LEN-1, fb) == NULL) {
+ 	    log_reason ("Premature end of script headers", r->filename, r);
+ 	    return SERVER_ERROR;
+         }
+ 
+ 	/* Delete terminal (CR?)LF */
+ 	
+ 	p = strlen(w);
+ 	if (p > 0 && w[p-1] == '\n')
+ 	{
+ 	    if (p > 1 && w[p-2] == '\015') w[p-2] = '\0';
+ 	    else w[p-1] = '\0';
+ 	}
+ 
+         if(w[0] == '\0') {
+ 	    kill_timeout (r);
+ 	    return OK;
+ 	}
+                                    
+ 	/* if we see a bogus header don't ignore it. Shout and scream */
+ 	
+         if(!(l = strchr(w,':'))) {
+ 	    char malformed[(sizeof MALFORMED_MESSAGE)+1+MALFORMED_HEADER_LENGTH_TO_SHOW];
+             strcpy(malformed, MALFORMED_MESSAGE);
+             strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
+ 
+ 	    if (!buffer)
+ 	      /* Soak up all the script output --- may save an outright kill */
+ 	      while (fgets(w, MAX_STRING_LEN-1, f) != NULL)
+ 		continue;
+ 	    
+ 	    kill_timeout (r);
+ 	    log_reason (malformed, r->filename, r);
+ 	    return SERVER_ERROR;
+         }
+ 
+         *l++ = '\0';
+ 	while (*l && isspace (*l)) ++l;
+ 	
+         if(!strcasecmp(w,"Content-type")) {
+ 
+ 	    /* Nuke trailing whitespace */
+ 	    
+ 	    char *endp = l + strlen(l) - 1;
+ 	    while (endp > l && isspace(*endp)) *endp-- = '\0';
+ 	    
+ 	    r->content_type = pstrdup (r->pool, l);
+ 	}
+         else if(!strcasecmp(w,"Status")) {
+             sscanf(l, "%d", &r->status);
+             r->status_line = pstrdup(r->pool, l);
+         }
+         else if(!strcasecmp(w,"Location")) {
+ 	    table_set (r->headers_out, w, l);
+         }   
+ 
+ /* The HTTP specification says that it is legal to merge duplicate
+  * headers into one.  Some browsers that support Cookies don't like
+  * merged headers and prefer that each Set-Cookie header is sent
+  * separately.  Lets humour those browsers.
+  */
+ 	else if(!strcasecmp(w, "Set-Cookie")) {
+ 	    table_add(r->err_headers_out, w, l);
+ 	}
+         else {
+ 	    table_merge (r->err_headers_out, w, l);
+         }
+     }
+ }
+ 
  int scan_script_header_err(request_rec *r, FILE *f, char *buffer)
  {
      char x[MAX_STRING_LEN];
***************
*** 272,278 ****
      
      while(1) {
  
! 	if (fgets(w, MAX_STRING_LEN-1, f) == NULL) {
  	    log_reason ("Premature end of script headers", r->filename, r);
  	    return SERVER_ERROR;
          }
--- 355,361 ----
      
      while(1) {
  
! 	if (fgets(w, MAX_STRING_LEN-1, fb) == NULL) {
  	    log_reason ("Premature end of script headers", r->filename, r);
  	    return SERVER_ERROR;
          }

Mime
View raw message