From 754480fd2ddb225923f9778fe3c6ff62e6ff2653 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Tue, 7 Nov 2000 22:41:09 +0000 Subject: [PATCH] Use apr_off_t for the content length, rather than long. Propagate through the byterange handling and ap_set_content_length(). [ ap_each_byterange() remains as an apr_size_t* so we don't mess up callers ] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86860 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_protocol.h | 12 ++++++-- include/httpd.h | 2 +- modules/http/http_protocol.c | 57 +++++++++++++++++++++++------------- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/include/http_protocol.h b/include/http_protocol.h index 953ab92bdd..276607f524 100644 --- a/include/http_protocol.h +++ b/include/http_protocol.h @@ -145,10 +145,10 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error); * Set the content length for this request * @param r The current request * @param length The new content length - * @return Always 0, can be safely ignored - * @deffunc int ap_set_content_length(request_rec *r, long length) + * @deffunc void ap_set_content_length(request_rec *r, apr_off_t length) */ -AP_DECLARE(int) ap_set_content_length(request_rec *r, long length); +AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length); + /** * Set the keepalive status for this request * @param r The current request @@ -156,6 +156,7 @@ AP_DECLARE(int) ap_set_content_length(request_rec *r, long length); * @deffunc int ap_set_keepalive(request_rec *r) */ AP_DECLARE(int) ap_set_keepalive(request_rec *r); + /** * Return the latest rational time from a request/mtime pair. Mtime is * returned unless it's in the future, in which case we return the current time. @@ -165,6 +166,7 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r); * @deffunc apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime) */ AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime); + /** * Construct an entity tag from the resource information. If it's a real * file, build in some of the file characteristics. @@ -175,18 +177,21 @@ AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime); * @deffunc char *ap_make_etag(request_rec *r, int force_weak) */ AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak); + /** * Set the E-tag outgoing header * @param The current request * @deffunc void ap_set_etag(request_rec *r) */ AP_DECLARE(void) ap_set_etag(request_rec *r); + /** * Set the last modified time for the file being sent * @param r The current request * @deffunc void ap_set_last_modified(request_rec *r) */ AP_DECLARE(void) ap_set_last_modified(request_rec *r); + /** * Implements condition GET rules for HTTP/1.1 specification. This function * inspects the client headers and determines if the response fulfills @@ -220,6 +225,7 @@ AP_DECLARE(int) ap_meets_conditions(request_rec *r); */ AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t length, apr_size_t *nbytes); + /** * Send an MMAP'ed file to the client * @param mm The MMAP'ed file to send diff --git a/include/httpd.h b/include/httpd.h index 12b62b63e3..2768ff00dd 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -701,7 +701,7 @@ struct request_rec { /** The Range: header */ const char *range; /** The "real" content length */ - long clength; + apr_off_t clength; /** bytes left to read */ long remaining; diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 56fa330d06..a6c0e92ad4 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -180,7 +180,8 @@ static const char *make_content_type(request_rec *r, const char *type) return type; } -static int parse_byterange(char *range, long clength, long *start, long *end) +static int parse_byterange(char *range, apr_off_t clength, + apr_off_t *start, apr_off_t *end) { char *dash = strchr(range, '-'); @@ -214,13 +215,18 @@ static int parse_byterange(char *range, long clength, long *start, long *end) return (*start > 0 || *end < clength - 1); } -static int internal_byterange(int, long *, request_rec *, const char **, - apr_off_t *, apr_size_t *); +/* forward declare */ +static int internal_byterange(int realreq, apr_off_t *tlength, request_rec *r, + const char **r_range, apr_off_t *offset, + apr_size_t *length); AP_DECLARE(int) ap_set_byterange(request_rec *r) { - const char *range, *if_range, *match; - long range_start, range_end; + const char *range; + const char *if_range; + const char *match; + apr_off_t range_start; + apr_off_t range_end; if (!r->clength || r->assbackwards) return 0; @@ -266,22 +272,26 @@ AP_DECLARE(int) ap_set_byterange(request_rec *r) r->byterange = 1; apr_table_setn(r->headers_out, "Content-Range", - apr_psprintf(r->pool, "bytes %ld-%ld/%ld", - range_start, range_end, r->clength)); + apr_psprintf(r->pool, + "bytes %" APR_OFF_T_FMT "-%" APR_OFF_T_FMT + "/%" APR_OFF_T_FMT, + range_start, range_end, r->clength)); apr_table_setn(r->headers_out, "Content-Length", - apr_psprintf(r->pool, "%ld", range_end - range_start + 1)); + apr_psprintf(r->pool, "%" APR_OFF_T_FMT, + range_end - range_start + 1)); } else { /* a multiple range */ const char *r_range = apr_pstrdup(r->pool, range + 6); - long tlength = 0; + apr_off_t tlength = 0; r->byterange = 2; r->boundary = apr_psprintf(r->pool, "%qx%lx", r->request_time, (long) getpid()); - while (internal_byterange(0, &tlength, r, &r_range, NULL, NULL)); + while (internal_byterange(0, &tlength, r, &r_range, NULL, NULL)) + continue; apr_table_setn(r->headers_out, "Content-Length", - apr_psprintf(r->pool, "%ld", tlength)); + apr_psprintf(r->pool, "%" APR_OFF_T_FMT, tlength)); } r->status = HTTP_PARTIAL_CONTENT; @@ -306,11 +316,12 @@ AP_DECLARE(int) ap_each_byterange(request_rec *r, apr_off_t *offset, * Either case will return 1 if it should be called again, and 0 * when done. */ -static int internal_byterange(int realreq, long *tlength, request_rec *r, +static int internal_byterange(int realreq, apr_off_t *tlength, request_rec *r, const char **r_range, apr_off_t *offset, - apr_size_t *length) + apr_size_t *length) { - long range_start, range_end; + apr_off_t range_start; + apr_off_t range_end; char *range; if (!**r_range) { @@ -332,17 +343,19 @@ static int internal_byterange(int realreq, long *tlength, request_rec *r, } range = ap_getword(r->pool, r_range, ','); - if (!parse_byterange(range, r->clength, &range_start, &range_end)) + if (!parse_byterange(range, r->clength, &range_start, &range_end)) { /* Skip this one */ return internal_byterange(realreq, tlength, r, r_range, offset, length); + } if (r->byterange > 1) { const char *ct = make_content_type(r, r->content_type); char ts[MAX_STRING_LEN]; - apr_snprintf(ts, sizeof(ts), "%ld-%ld/%ld", range_start, range_end, - r->clength); + apr_snprintf(ts, sizeof(ts), + "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT, + range_start, range_end, r->clength); if (realreq) (void) checked_bputstrs(r, CRLF "--", r->boundary, CRLF "Content-type: ", ct, @@ -355,7 +368,9 @@ static int internal_byterange(int realreq, long *tlength, request_rec *r, if (realreq) { *offset = range_start; - *length = range_end - range_start + 1; + + /* ### we need to change ap_each_byterange() to fix this */ + *length = (apr_size_t) (range_end - range_start + 1); } else { *tlength += range_end - range_start + 1; @@ -363,11 +378,11 @@ static int internal_byterange(int realreq, long *tlength, request_rec *r, return 1; } -AP_DECLARE(int) ap_set_content_length(request_rec *r, long clength) +AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t clength) { r->clength = clength; - apr_table_setn(r->headers_out, "Content-Length", apr_psprintf(r->pool, "%ld", clength)); - return 0; + apr_table_setn(r->headers_out, "Content-Length", + apr_psprintf(r->pool, "%" APR_OFF_T_FMT, clength)); } AP_DECLARE(int) ap_set_keepalive(request_rec *r) -- 2.40.0