static int translate_thumb(request_rec *r) { int res = ap_core_translate(r); if (res != OK || !r->filename) { return res; } char *thumb_uri; char *size; apr_finfo_t finfo; if (parse_request_uri(r, &thumb_uri, &size) != APR_SUCCESS) { return DECLINED; } char *path = uri2thumbpath(r, thumb_uri, size); if (apr_stat(&finfo, path, APR_FINFO_INODE, r->pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Thumbnail does not exist: %s", path); path = no_image_path(r, size); r->filename = path; r->status = HTTP_NOT_FOUND; } else { r->filename = path; } return OK; }
// Request-Line = Method SP Request-URI SP HTTP-Version CRLF const char* parse_request_line(unsigned char** p) { if (parse_method(p)) return ERR; if (parse_space(p)) return ERR; if (parse_request_uri(p)) return ERR; if (parse_space(p)) return ERR; if (parse_http_version(p)) return ERR; return parse_crlf(p); }
/** * Parses the client request. The request is parsed to properly consume * the request data, identifying GET and HEAD HTTP methods. Most of the * data read is actually discarded, in the current implementation. */ void parse_request(struct parser *p) { int r; if(!read_socket(p)) return; switch (p->state) { case PARSING_START: p->mark = 0; p->state = PARSING_METHOD; debug("parse started"); case PARSING_METHOD: r = parse_request_method(p); if (r != PARSING_DONE) break; p->state = PARSING_URI; debug("parsed method: %d", p->request.method); case PARSING_URI: r = parse_request_uri(p); if (r != PARSING_DONE) break; p->state = PARSING_VERSION; debug("parsed uri"); case PARSING_VERSION: r = parse_http_version(p); if (r != PARSING_DONE) break; p->state = PARSING_HEADERS; debug("parsed http version"); case PARSING_HEADERS: case PARSING_HEADER_NAME: case PARSING_HEADER_NAME_ANY: case PARSING_HEADER_VALUE: case PARSING_HEADER_CONTENT_LENGTH: r = parse_headers(p); if (r != PARSING_DONE) break; p->state = PARSING_BODY; debug("parsed headers"); debug("content-length: %ld", p->request.content_length); case PARSING_BODY: r = parse_body(p); if (r != PARSING_DONE) break; p->state = PARSING_DONE; debug("parsed body"); return; default: debug("illegal parser state: %d", p->state); p->state = PARSING_ERROR; p->error = E_PARSE; return; } if (r == PARSING_ERROR) { p->state = PARSING_ERROR; if (p->error == E_NONE) p->error = E_PARSE; } return; }