PATCH: add PUT support for CGIs

David Jeske <[email protected]> Thu, 25 Mar 2004 00:42:22 -0800
Newsgroups gmane.network.mathopd
Message-ID <[email protected]>
This patch adds support for handling HTTP PUT requests for CGIs
only. They are basically just like POST.


-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + [email protected]
mathopd-1.5p2-addputcgi.patch (text/plain, 4.3 KB)
diff -c -r mathopd-1.5p2/src/mathopd.h mathopd-1.5p2-jeske/src/mathopd.h
*** mathopd-1.5p2/src/mathopd.h	Mon Feb 23 07:01:13 2004
--- mathopd-1.5p2-jeske/src/mathopd.h	Wed Mar 24 14:15:13 2004
***************
*** 80,86 ****
  	M_UNKNOWN,
  	M_HEAD,
  	M_GET,
! 	M_POST
  };
  
  enum connection_state {
--- 80,87 ----
  	M_UNKNOWN,
  	M_HEAD,
  	M_GET,
! 	M_POST,
! 	M_PUT
  };
  
  enum connection_state {
diff -c -r mathopd-1.5p2/src/request.c mathopd-1.5p2-jeske/src/request.c
*** mathopd-1.5p2/src/request.c	Fri Feb 13 06:43:28 2004
--- mathopd-1.5p2-jeske/src/request.c	Wed Mar 24 14:14:55 2004
***************
*** 57,62 ****
--- 57,64 ----
  static const char m_get[] =			"GET";
  static const char m_head[] =			"HEAD";
  static const char m_post[] =			"POST";
+ static const char m_put[] =			"PUT";
+ 
  
  static time_t timerfc(const char *s)
  {
***************
*** 533,541 ****
  		return process_cgi(r);
  	if (r->status)
  		return 0;
! 	if (r->method == M_POST) {
  		if (debug)
! 			log_d("POST to specialty rejected");
  		r->status = 405;
  		return 0;
  	}
--- 535,543 ----
  		return process_cgi(r);
  	if (r->status)
  		return 0;
! 	if (r->method == M_POST || r->method == M_PUT) {
  		if (debug)
! 			log_d("POST/PUT to specialty rejected");
  		r->status = 405;
  		return 0;
  	}
***************
*** 598,607 ****
  		r->status = 404;
  		return 1;
  	}
! 	if (r->method == M_POST) {
  		close_rfd(r);
  		if (debug)
! 			log_d("POST to file rejected");
  		r->status = 405;
  		return 0;
  	}
--- 600,609 ----
  		r->status = 404;
  		return 1;
  	}
! 	if (r->method == M_POST || r->method == M_PUT) {
  		close_rfd(r);
  		if (debug)
! 			log_d("POST/PUT to file rejected");
  		r->status = 405;
  		return 0;
  	}
***************
*** 666,672 ****
  
  	d = 0;
  	v = r->cn->s->children;
! 	if (r->host)
  		while (v) {
  			if (v->host) {
  				if (strcmp(r->host, v->host) == 0)
--- 668,675 ----
  
  	d = 0;
  	v = r->cn->s->children;
! 	if (r->host && r->host[0]) {
! 	  log_d("find specific host '%s'!",r->host);
  		while (v) {
  			if (v->host) {
  				if (strcmp(r->host, v->host) == 0)
***************
*** 675,686 ****
  				d = v;
  			v = v->next;
  		}
! 	else
  		while (v) {
! 			if (v->host == 0 && v->anyhost == 0)
  				break;
  			v = v->next;
  		}
  	if (v == 0) {
  		if (d == 0)
  			return -1;
--- 678,693 ----
  				d = v;
  			v = v->next;
  		}
! 	} else {
!                 log_d("find anyhost!");
  		while (v) {
! 		  log_d("testing host: %s anyhost:%d", v->host,v->anyhost);
! 			if (v->anyhost == 1)
  				break;
  			v = v->next;
  		}
+                 log_d("failed to find anyhost!");
+         }
  	if (v == 0) {
  		if (d == 0)
  			return -1;
***************
*** 861,869 ****
  			if (r->status)
  				return 1;
  			if (r->path_args[1] == 0 && r->c->auto_index_command) {
! 				if (r->method == M_POST) {
  					if (debug)
! 						log_d("POST to AutoIndexCommand rejected");
  					r->status = 405;
  					return 0;
  				}
--- 868,876 ----
  			if (r->status)
  				return 1;
  			if (r->path_args[1] == 0 && r->c->auto_index_command) {
! 				if (r->method == M_POST || r->method == M_PUT) {
  					if (debug)
! 						log_d("POST/PUT to AutoIndexCommand rejected");
  					r->status = 405;
  					return 0;
  				}
***************
*** 1185,1191 ****
  			r->method = M_HEAD;
  		else if (strcmp(s, m_post) == 0)
  			r->method = M_POST;
! 		else {
  			if (debug)
  				log_d("method \"%s\" not implemented", s);
  			r->status = 501;
--- 1192,1200 ----
  			r->method = M_HEAD;
  		else if (strcmp(s, m_post) == 0)
  			r->method = M_POST;
! 		else if (strcmp(s, m_put) == 0)
! 		  r->method = M_PUT;
!                 else {
  			if (debug)
  				log_d("method \"%s\" not implemented", s);
  			r->status = 501;
***************
*** 1286,1295 ****
  			if (parse_range_header(r, s) == -1)
  				log_d("ignoring Range header \"%s\"", s);
  		}
! 	} else if (r->method == M_POST) {
  		if (r->in_content_length == 0) {
  			if (debug)
! 				log_d("POST: length required");
  			r->status = 411;
  			return 0;
  		}
--- 1295,1304 ----
  			if (parse_range_header(r, s) == -1)
  				log_d("ignoring Range header \"%s\"", s);
  		}
! 	} else if (r->method == M_POST || r->method == M_PUT) {
  		if (r->in_content_length == 0) {
  			if (debug)
! 				log_d("POST/PUT: length required");
  			r->status = 411;
  			return 0;
  		}