byterange_filter.c revision e8f95a682820a599fe41b22977010636be5c2717
/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* byterange_filter.c --- HTTP byterange filter and friends.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#include "apr_signal.h"
#define APR_WANT_STDIO /* for sscanf */
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#define CORE_PRIVATE
#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_log.h" /* For errors detected in basic auth common
* support code... */
#include "apr_date.h" /* For apr_date_parse_http and APR_DATE_BAD */
#include "util_charset.h"
#include "util_ebcdic.h"
#include "util_time.h"
#include "mod_core.h"
#include <stdarg.h>
#endif
#include <unistd.h>
#endif
{
char *errp;
if (!dash) {
return 0;
}
/* In the form "-5" */
return 0;
}
}
else {
*dash++ = '\0';
return 0;
}
if (*dash) {
return 0;
}
}
else { /* "5-" */
}
}
if (*start < 0) {
*start = 0;
}
}
return -1;
}
}
static int ap_set_byterange(request_rec *r);
typedef struct byterange_ctx {
int num_ranges;
char *boundary;
char *bound_head;
/*
* Here we try to be compatible with clients that want multipart/x-byteranges
* instead of multipart/byteranges (also see above), as per HTTP/1.1. We
* look for the Request-Range header (e.g. Netscape 2 and 3) as an indication
* that the browser supports an older protocol. We also check User-Agent
* for Microsoft Internet Explorer 3, which needs this as well.
*/
static int use_range_x(request_rec *r)
{
const char *ua;
}
#define PARTITION_ERR_FMT "apr_brigade_partition() failed " \
{
request_rec *r = f->r;
conn_rec *c = r->connection;
apr_bucket *e;
char *current;
int found = 0;
int num_ranges;
/* Iterate through the brigade until reaching EOS or a bucket with
* unknown length. */
for (e = APR_BRIGADE_FIRST(bb);
e = APR_BUCKET_NEXT(e)) {
}
/* Don't attempt to do byte range work if this brigade doesn't
* contain an EOS, or if any of the buckets has an unknown length;
* this avoids the cases where it is expensive to perform
* byteranging (i.e. may require arbitrary amounts of memory). */
if (!APR_BUCKET_IS_EOS(e) || clength <= 0) {
}
num_ranges = ap_set_byterange(r);
/* We have nothing to do, get out of the way. */
if (num_ranges == 0) {
}
/* create a brigade in case we never call ap_save_brigade() */
/* Is ap_make_content_type required here? */
"byteranges; boundary=",
CRLF "Content-type: ",
CRLF "Content-range: bytes ",
NULL);
}
/* this brigade holds what we will be sending */
&range_end))) {
apr_bucket *e2;
apr_bucket *ec;
if (rv == -1) {
continue;
}
/* These calls to apr_brigage_partition should only fail in
* pathological cases, e.g. a file being truncated whilst
* being served. */
continue;
}
continue;
}
found = 1;
/* For single range requests, we must produce Content-Range header.
* Otherwise, we need to produce the multipart boundaries.
*/
}
else {
char *ts;
r->pool, c->bucket_alloc);
c->bucket_alloc);
}
do {
const char *str;
/* As above; this should not fail since the bucket has
* a known length, but just to be sure, this takes
* care of uncopyable buckets that do somehow manage
* to slip through. */
/* XXX: check for failure? */
}
}
if (found == 0) {
/* bsend is assumed to be empty if we get here. */
r->pool, c->bucket_alloc);
e = apr_bucket_eos_create(c->bucket_alloc);
}
char *end;
/* add the final boundary */
}
e = apr_bucket_eos_create(c->bucket_alloc);
/* we're done with the original content - all of our data is in bsend. */
/* send our multipart output */
}
static int ap_set_byterange(request_rec *r)
{
const char *range;
const char *if_range;
const char *match;
const char *ct;
int num_ranges;
if (r->assbackwards) {
return 0;
}
/* Check for Range request-header (HTTP/1.1) or Request-Range for
* byte-ranges (e.g. Netscape Navigator 2-3).
*
* We support this form, with Request-Range, and (farther down) we
* send multipart/x-byteranges instead of multipart/byteranges for
* Request-Range based requests to work around a bug in Netscape
* Navigator 2-3 and MSIE 3.
*/
}
return 0;
}
/* is content already a single range? */
return 0;
}
/* is content already a multiple range? */
return 0;
}
/* Check the If-Range header for Etag or Date.
* Note that this check will return false (as required) if either
* of the two etags are weak.
*/
if (if_range[0] == '"') {
return 0;
}
}
return 0;
}
}
/* a single range */
num_ranges = 1;
}
else {
/* a multiple range */
num_ranges = 2;
}
r->status = HTTP_PARTIAL_CONTENT;
return num_ranges;
}