log_d("method_s = \"%.80s\"", r->method_s);
log_d("method_s = \"%s\"", r->method_s);
static int process_headers(struct request *r){	char *l, *u, *s, *t;	unsigned long x, y;	time_t i;	while (1) {		l = getline(r->cn->input);		if (l == 0) {			return -1;		}		while (*l == ' ')			++l;		u = strchr(l, ' ');		if (u)			break;		log_d("ignoring garbage \"%.80s\" from %s", l, r->cn->ip);	}	r->method_s = l;	*u++ = 0;	while (*u == ' ')		++u;	s = strrchr(u, ' ');	if (s) {		r->version = s + 1;		do {			*s-- = 0;		} while (*s == ' ');	}	r->url = u;	s = strchr(u, '?');	if (s) {		r->args = s + 1;		*s = 0;	}	while ((l = getline(r->cn->input)) != 0) {		s = strchr(l, ':');		if (s == 0)			continue;		*s++ = 0;		while (*s == ' ')			++s;		if (*s == 0)			continue;		if (!strcasecmp(l, "User-agent"))			r->user_agent = s;		else if (!strcasecmp(l, "Referer"))			r->referer = s;		else if (!strcasecmp(l, "From"))			r->from = s;		else if (!strcasecmp(l, "Authorization"))			r->authorization = s;		else if (!strcasecmp(l, "Cookie"))			r->cookie = s;		else if (!strcasecmp(l, "Host"))			r->host = s;		else if (!strcasecmp(l, "Connection"))			r->connection = s;		else if (!strcasecmp(l, "If-modified-since"))			r->ims_s = s;		else if (!strcasecmp(l, "Content-type"))			r->in_content_type = s;		else if (!strcasecmp(l, "Content-length"))			r->in_content_length = s;	}	if (debug) {		if (r->method_s)			log_d("method_s = \"%.80s\"", r->method_s);		if (r->version)			log_d("version = \"%.80s\"", r->version);		if (r->url)			log_d("url = \"%.80s\"", r->url);		if (r->args)			log_d("args = \"%.80s\"", r->args);		if (r->user_agent)			log_d("user_agent = \"%.80s\"", r->user_agent);		if (r->referer)			log_d("referer = \"%.80s\"", r->referer);		if (r->from)			log_d("from = \"%.80s\"", r->from);		if (r->authorization)			log_d("authorization = \"%.80s\"", r->authorization);		if (r->cookie)			log_d("cookie = \"%.80s\"", r->cookie);		if (r->host)			log_d("host = \"%.80s\"", r->host);		if (r->connection)			log_d("connection = \"%.80s\"", r->connection);		if (r->ims_s)			log_d("ims_s = \"%.80s\"", r->ims_s);		if (r->in_content_type)			log_d("in_content_type = \"%.80s\"", r->in_content_type);		if (r->in_content_length)			log_d("in_content_length = \"%.80s\"", r->in_content_length);	}	s = r->method_s;	if (s == 0) {		log_d("method_s == 0 !?");		return -1;	}	if (strcmp(s, m_get) == 0) {		r->method = M_GET;	} else {		if (r->cn->assbackwards) {			log_d("method \"%.80s\" not implemented for old-style connections", s);			return 501;		}		if (strcmp(s, m_head) == 0)			r->method = M_HEAD;		else if (strcmp(s, m_post) == 0)			r->method = M_POST;		else {			log_d("method \"%.80s\" not implemented", s);			return 501;		}	}	s = r->url;	if (s == 0) {		log_d("url == 0 !?");		return -1;	}	if (strlen(s) > STRLEN)		return 400;	if (unescape_url(s, r->path) == -1)		return 400;	if (r->path[0] != '/')		return 400;	if (r->cn->assbackwards) {		r->protocol_major = 0;		r->protocol_minor = 9;	} else {		s = r->version;		if (s == 0) {			log_d("version == 0 !?");			return -1;		}		if (strncmp(s, "HTTP/", 5)) {			log_d("unsupported version \"%.32s\" from %s", s, r->cn->ip);			return 400;		}		t = strchr(s + 5, '.');		if (t == 0) {			log_d("unsupported version \"%.32s\" from %s", s, r->cn->ip);			return 400;		}		*t = 0;		x = atoi(s + 5);		y = atoi(t + 1);		*t = '.';		if (x != 1 || y > 1) {			log_d("unsupported version \"%.32s\" from %s", s, r->cn->ip);			return 505;		}		r->protocol_major = x;		r->protocol_minor = y;		s = r->connection;		if (y) {			r->cn->keepalive = !(s && strcasecmp(s, "Close") == 0);		} else {			r->cn->keepalive = s && strcasecmp(s, "Keep-Alive") == 0;		}	}	if (r->method == M_GET) {		s = r->ims_s;		if (s) {			i = timerfc(s);			if (i == (time_t) -1) {				log_d("illegal date \"%.80s\" in If-Modified-Since", s);				return 400;			}			r->ims = i;		}	}	return 0;}