ap_overlap_tables(r->headers_in, tmp_headers, AP_OVERLAP_TABLES_MERGE);
}
+ap_status_t ap_setup_input(request_rec *r)
+{
+ BUFF *temp = NULL;
+ ap_iol *iol;
+ ap_file_t *fd = NULL;
+ ap_status_t status;
+
+ if (!r->input) {
+ if ((status = ap_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool)) != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
+ "file permissions deny server access: %s", r->filename);
+ return status;
+ }
+
+ iol = ap_create_file_iol(fd);
+ if (!iol)
+ return APR_EBADF;
+ temp = ap_bcreate(r->pool, B_RD);
+ ap_bpush_iol(temp, iol);
+ r->input = temp;
+ }
+ return APR_SUCCESS;
+}
+
request_rec *ap_read_request(conn_rec *conn)
{
request_rec *r;
long chunk_start = 0;
unsigned long max_body;
ap_status_t rv;
+ BUFF *used_buff;
+
+ used_buff = r->input ? r->input : r->connection->client;
if (!r->read_chunked) { /* Content-length read */
len_to_read = (r->remaining > bufsiz) ? bufsiz : r->remaining;
- rv = ap_bread(r->connection->client, buffer, len_to_read, &len_read);
+ rv = ap_bread(used_buff, buffer, len_to_read, &len_read);
if (len_read == 0) { /* error or eof */
if (rv != APR_SUCCESS) {
r->connection->keepalive = -1;
if (r->remaining == 0) { /* Start of new chunk */
- chunk_start = getline(buffer, bufsiz, r->connection->client, 0);
+ chunk_start = getline(buffer, bufsiz, used_buff, 0);
if ((chunk_start <= 0) || (chunk_start >= (bufsiz - 1))
|| !ap_isxdigit(*buffer)) {
r->connection->keepalive = -1;
len_read = chunk_start;
while ((bufsiz > 1) && ((len_read =
- getline(buffer, bufsiz, r->connection->client, 1)) > 0)) {
+ getline(buffer, bufsiz, used_buff, 1)) > 0)) {
if (len_read != (bufsiz - 1)) {
buffer[len_read++] = CR; /* Restore footer line end */
len_to_read = (r->remaining > bufsiz) ? bufsiz : r->remaining;
- (void) ap_bread(r->connection->client, buffer, len_to_read, &len_read);
+ (void) ap_bread(used_buff, buffer, len_to_read, &len_read);
if (len_read == 0) { /* error or eof */
r->connection->keepalive = -1;
return -1;
r->remaining -= len_read;
if (r->remaining == 0) { /* End of chunk, get trailing CRLF */
- if ((c = ap_bgetc(r->connection->client)) == CR) {
- c = ap_bgetc(r->connection->client);
+ if ((c = ap_bgetc(used_buff)) == CR) {
+ c = ap_bgetc(used_buff);
}
if (c != LF) {
r->connection->keepalive = -1;
*/
API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r)
{
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
long len = r->finfo.size;
#ifdef HAVE_SENDFILE
if (!r->chunked) {
ap_status_t rv;
- ap_bsetopt(r->connection->client, BO_TIMEOUT,
+ ap_bsetopt(used_buff, BO_TIMEOUT,
r->connection->keptalive
? &r->server->keep_alive_timeout
: &r->server->timeout);
- ap_bflush(r->connection->client);
- rv = iol_sendfile(r->connection->client->iol,
+ ap_bflush(used_buff);
+ rv = iol_sendfile(used_buff->iol,
fd, /* The file to send */
NULL, /* header and trailer iovecs */
0, /* Offset in file to begin sending from */
"ap_send_fd: iol_sendfile failed.");
}
if (r->connection->keptalive) {
- ap_bsetopt(r->connection->client, BO_TIMEOUT,
+ ap_bsetopt(used_buff, BO_TIMEOUT,
&r->server->timeout);
}
}
ap_ssize_t w;
ap_ssize_t n;
ap_status_t rv;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (length == 0)
return 0;
o = 0;
while (n && !ap_is_aborted(r->connection)) {
- rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
+ rv = ap_bwrite(used_buff, &buf[o], n, &w);
if (w > 0) {
total_bytes_sent += w;
n -= w;
if (!ap_is_aborted(r->connection)) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before send body completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
break;
ap_ssize_t w;
ap_ssize_t n;
ap_status_t rv;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (length == 0) {
return 0;
o = 0;
while (n && !ap_is_aborted(r->connection)) {
- rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
+ rv = ap_bwrite(used_buff, &buf[o], n, &w);
if (w > 0) {
total_bytes_sent += w;
n -= w;
if (!ap_is_aborted(r->connection)) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before rflush completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
break;
ap_ssize_t w;
ap_status_t rv;
char *addr;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (length == 0)
return 0;
while (n && !r->connection->aborted) {
ap_mmap_offset((void**)&addr, mm, offset);
- rv = ap_bwrite(r->connection->client, addr, n, &w);
+ rv = ap_bwrite(used_buff, addr, n, &w);
if (w > 0) {
total_bytes_sent += w;
n -= w;
else {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before send mmap completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
break;
}
API_EXPORT(int) ap_rputc(int c, request_rec *r)
{
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (r->connection->aborted)
return EOF;
- if (ap_bputc(c, r->connection->client) < 0) {
+ if (ap_bputc(c, used_buff) < 0) {
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO,
- ap_berror(r->connection->client), r,
+ ap_berror(used_buff), r,
"client stopped connection before rputc completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return EOF;
API_EXPORT(int) ap_rputs(const char *str, request_rec *r)
{
int rcode;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (r->connection->aborted)
return EOF;
- rcode = ap_bputs(str, r->connection->client);
+ rcode = ap_bputs(str, used_buff);
if (rcode < 0) {
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO,
- ap_berror(r->connection->client), r,
+ ap_berror(used_buff), r,
"client stopped connection before rputs completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return EOF;
{
ap_ssize_t n;
ap_status_t rv;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (r->connection->aborted)
return EOF;
- rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
+ rv = ap_bwrite(used_buff, buf, nbyte, &n);
if (n < 0) {
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before rwrite completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return EOF;
API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list ap)
{
int n;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (r->connection->aborted)
return -1;
- n = ap_vbprintf(r->connection->client, fmt, ap);
+ n = ap_vbprintf(used_buff, fmt, ap);
if (n < 0) {
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO,
- ap_berror(r->connection->client), r,
+ ap_berror(used_buff), r,
"client stopped connection before vrprintf completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return -1;
{
va_list vlist;
int n;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
if (r->connection->aborted)
return -1;
va_start(vlist, fmt);
- n = ap_vbprintf(r->connection->client, fmt, vlist);
+ n = ap_vbprintf(used_buff, fmt, vlist);
va_end(vlist);
if (n < 0) {
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO,
- ap_berror(r->connection->client), r,
+ ap_berror(used_buff), r,
"client stopped connection before rprintf completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return -1;
ap_ssize_t i;
int j, k;
const char *x;
- BUFF *fb = r->connection->client;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
ap_status_t rv;
if (r->connection->aborted)
if (x == NULL)
break;
j = strlen(x);
- rv = ap_bwrite(fb, x, j, &i);
+ rv = ap_bwrite(used_buff, x, j, &i);
if (i != j) {
va_end(args);
if (!r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before rvputs completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return EOF;
API_EXPORT(int) ap_rflush(request_rec *r)
{
ap_status_t rv;
+ BUFF *used_buff = r->output ? r->output : r->connection->client;
- if ((rv = ap_bflush(r->connection->client)) != APR_SUCCESS) {
+ if ((rv = ap_bflush(used_buff)) != APR_SUCCESS) {
if (!ap_is_aborted(r->connection)) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
"client stopped connection before rflush completed");
- ap_bsetflag(r->connection->client, B_EOUT, 1);
+ ap_bsetflag(used_buff, B_EOUT, 1);
r->connection->aborted = 1;
}
return EOF;
const char *handler;
char *p;
size_t handler_len;
- int result = HTTP_INTERNAL_SERVER_ERROR;
+ int result;
- if (r->handler) {
- handler = r->handler;
- handler_len = strlen(handler);
- }
- else {
- handler = r->content_type ? r->content_type : ap_default_type(r);
- if ((p = strchr(handler, ';')) != NULL) { /* MIME type arguments */
- while (p > handler && p[-1] == ' ')
- --p; /* strip trailing spaces */
- handler_len = p - handler;
- }
- else {
+ do {
+ result = DECLINED;
+ if (r->handler) {
+ handler = r->handler;
handler_len = strlen(handler);
- }
- }
-
- /* Pass one --- direct matches */
+ }
+ else {
+ handler = r->content_type ? r->content_type : ap_default_type(r);
+ if ((p = strchr(handler, ';')) != NULL) { /* MIME type arguments */
+ while (p > handler && p[-1] == ' ')
+ --p; /* strip trailing spaces */
+ handler_len = p - handler;
+ }
+ else {
+ handler_len = strlen(handler);
+ }
+ }
- for (handp = handlers; handp->hr.content_type; ++handp) {
- if (handler_len == handp->len
- && !strncmp(handler, handp->hr.content_type, handler_len)) {
- result = (*handp->hr.handler) (r);
+ /* Pass one --- direct matches */
+
+ for (handp = handlers; handp->hr.content_type; ++handp) {
+ if (handler_len == handp->len
+ && !strncmp(handler, handp->hr.content_type, handler_len)) {
+ result = (*handp->hr.handler) (r);
- if (result != DECLINED)
- return result;
+ if (result != DECLINED)
+ break;
+ }
}
- }
- /* Pass two --- wildcard matches */
+ /* Pass two --- wildcard matches */
- for (handp = wildhandlers; handp->hr.content_type; ++handp) {
- if (handler_len >= handp->len
- && !strncmp(handler, handp->hr.content_type, handp->len)) {
- result = (*handp->hr.handler) (r);
+ if (result == DECLINED) {
+ for (handp = wildhandlers; handp->hr.content_type; ++handp) {
+ if (handler_len >= handp->len
+ && !strncmp(handler, handp->hr.content_type, handp->len)) {
+ result = (*handp->hr.handler) (r);
- if (result != DECLINED)
- return result;
- }
- }
+ if (result != DECLINED)
+ break;
+ }
+ }
+ }
+ } while (result == RERUN_HANDLERS);
if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
"handler \"%s\" not found for: %s", r->handler, r->filename);
+ return HTTP_INTERNAL_SERVER_ERROR;
}
- return HTTP_INTERNAL_SERVER_ERROR;
+
+ return result;
}
int g_bDebugHooks;