int process_option_line(request * req) { char c, *value, *line = req->header_line; /* Start by aggressively hacking the in-place copy of the header line */ #ifdef FASCIST_LOGGING log_error_time(); fprintf(stderr, "%s:%d - Parsing \"%s\"\n", __FILE__, __LINE__, line); #endif value = strchr(line, ':'); if (value == NULL) return 0; *value++ = '\0'; /* overwrite the : */ to_upper(line); /* header types are case-insensitive */ while ((c = *value) && (c == ' ' || c == '\t')) value++; if (!memcmp(line, "IF_MODIFIED_SINCE", 18) && !req->if_modified_since) req->if_modified_since = value; else if (!memcmp(line, "CONTENT_TYPE", 13) && !req->content_type) req->content_type = value; else if (!memcmp(line, "CONTENT_LENGTH", 15) && !req->content_length) req->content_length = value; else if (!memcmp(line, "CONNECTION", 11) && ka_max && req->keepalive != KA_STOPPED) { req->keepalive = (!strncasecmp(value, "Keep-Alive", 10) ? KA_ACTIVE : KA_STOPPED); } /* #ifdef ACCEPT_ON */ else if (!memcmp(line, "ACCEPT", 7)) add_accept_header(req, value); /* #endif */ /* Need agent and referer for logs */ else if (!memcmp(line, "REFERER", 8)) { req->header_referer = value; if (!add_cgi_env(req, "REFERER", value, 1)) return 0; } else if (!memcmp(line, "USER_AGENT", 11)) { req->header_user_agent = value; if (!add_cgi_env(req, "USER_AGENT", value, 1)) return 0; } else { if (!add_cgi_env(req, line, value, 1)) return 0; } return 1; }
int process_option_line(request * req) { char c, *value, *line = req->header_line; int eat_line = 0; /* Start by aggressively hacking the in-place copy of the header line */ #ifdef FASCIST_LOGGING fprintf(stderr, "\"%s\"\n", line); #endif value = strchr(line, ':'); if (value == NULL) return 0; *value++ = '\0'; /* overwrite the : */ to_upper(line); /* header types are case-insensitive */ while ((c = *value) && (c == ' ' || c == '\t')) value++; if (!memcmp(line, "IF_MODIFIED_SINCE", 18) && !req->if_modified_since) req->if_modified_since = value; else if (!memcmp(line, "CONTENT_TYPE", 13) && !req->content_type) req->content_type = value; else if (!memcmp(line, "CONTENT_LENGTH", 15) && !req->content_length) req->content_length = value; else if (!memcmp(line, "HOST",5) && !req->host) req->host = value; #ifndef NO_REFERER_LOG else if (!memcmp(line, "REFERER", 8) && !req->referer) req->referer = value; #endif #ifdef USE_AUTH else if (!memcmp(line,"AUTHORIZATION",14) && !req->authorization) req->authorization = value; #endif #ifndef NO_AGENT_LOG else if (!memcmp(line, "USER_AGENT", 11) && !req->user_agent) req->user_agent = value; #endif else if (!memcmp(line, "CONNECTION", 11) && ka_max && req->keepalive != KA_STOPPED) req->keepalive = (!strncasecmp(value, "Keep-Alive", 10) ? KA_ACTIVE : KA_STOPPED); #ifdef ACCEPT_ON else if (!memcmp(line, "ACCEPT", 7)) { add_accept_header(req, value); eat_line = 1; } #endif /* Silently ignore unknown header lines unless is_cgi */ else { add_cgi_env(req, line, value); eat_line = 1; } if (eat_line) { int throw = (req->header_end - req->header_line) + 1; memmove(req->header_line, req->header_end + 1, CLIENT_STREAM_SIZE - ((req->header_end + 1) - req->client_stream)); req->client_stream_pos -= throw; return(throw); } return 0; }
int process_option_line(request * req) { char c, *value, *line = req->header_line; /* Start by aggressively hacking the in-place copy of the header line */ #ifdef FASCIST_LOGGING log_error_time(); fprintf(stderr, "%s:%d - Parsing \"%s\"\n", __FILE__, __LINE__, line); #endif value = strchr(line, ':'); if (value == NULL) { log_error_doc(req); fprintf(stderr, "header \"%s\" does not contain ':'\n", line); return 0; } *value++ = '\0'; /* overwrite the : */ to_upper(line); /* header types are case-insensitive */ /* the code below *does* catch '\0' due to the c = *value test */ while ((c = *value) && (c == ' ' || c == '\t')) value++; /* if c == '\0' there was no 'value' for the key */ if (c == '\0') { return 0; } switch (line[0]) { case 'A': if (!memcmp(line, "ACCEPT", 7)) { #ifdef ACCEPT_ON add_accept_header(req, value); #endif return 1; } break; case 'C': if (!memcmp(line, "CONTENT_TYPE", 13) && !req->content_type) { req->content_type = value; return 1; } else if (!memcmp(line, "CONTENT_LENGTH", 15) && !req->content_length) { req->content_length = value; return 1; } else if (!memcmp(line, "CONNECTION", 11) && ka_max && req->keepalive != KA_STOPPED) { req->keepalive = (!strncasecmp(value, "Keep-Alive", 10) ? KA_ACTIVE : KA_STOPPED); return 1; } break; case 'H': if (!memcmp(line, "HOST", 5) && !req->header_host) { req->header_host = value; /* may be complete garbage! */ return 1; } break; case 'I': if (!memcmp(line, "IF_MODIFIED_SINCE", 18) && !req->if_modified_since) { req->if_modified_since = value; return 1; } break; case 'R': /* Need agent and referer for logs */ if (!memcmp(line, "REFERER", 8)) { req->header_referer = value; if (!add_cgi_env(req, "REFERER", value, 1)) { /* errors already logged */ return 0; } } else if (!memcmp(line, "RANGE", 6)) { if (req->ranges && req->ranges->stop == INT_MAX) { /* there was an error parsing, ignore */ return 1; } else if (!range_parse(req, value)) { /* unable to parse range */ send_r_invalid_range(req); return 0; } /* req->ranges */ } break; case 'U': if (!memcmp(line, "USER_AGENT", 11)) { req->header_user_agent = value; if (!add_cgi_env(req, "USER_AGENT", value, 1)) { /* errors already logged */ return 0; } return 1; } break; default: /* no default */ break; } /* switch */ return add_cgi_env(req, line, value, 1); }